diff options
author | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2017-05-30 12:48:17 +0200 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2017-05-30 12:48:17 +0200 |
commit | 881da28418d380042aa95a97f0cbd42560a64f7c (patch) | |
tree | a794dff3274695e99c651902dde93d934ea7a5af /Source/JavaScriptCore/bindings | |
parent | 7e104c57a70fdf551bb3d22a5d637cdcbc69dbea (diff) | |
parent | 0fcedcd17cc00d3dd44c718b3cb36c1033319671 (diff) | |
download | qtwebkit-881da28418d380042aa95a97f0cbd42560a64f7c.tar.gz |
Merge 'wip/next' into dev
Change-Id: Iff9ee5e23bb326c4371ec8ed81d56f2f05d680e9
Diffstat (limited to 'Source/JavaScriptCore/bindings')
-rw-r--r-- | Source/JavaScriptCore/bindings/ScriptFunctionCall.cpp | 157 | ||||
-rw-r--r-- | Source/JavaScriptCore/bindings/ScriptFunctionCall.h | 87 | ||||
-rw-r--r-- | Source/JavaScriptCore/bindings/ScriptObject.cpp | 53 | ||||
-rw-r--r-- | Source/JavaScriptCore/bindings/ScriptObject.h | 55 | ||||
-rw-r--r-- | Source/JavaScriptCore/bindings/ScriptValue.cpp | 162 | ||||
-rw-r--r-- | Source/JavaScriptCore/bindings/ScriptValue.h | 78 |
6 files changed, 592 insertions, 0 deletions
diff --git a/Source/JavaScriptCore/bindings/ScriptFunctionCall.cpp b/Source/JavaScriptCore/bindings/ScriptFunctionCall.cpp new file mode 100644 index 000000000..d6745bebc --- /dev/null +++ b/Source/JavaScriptCore/bindings/ScriptFunctionCall.cpp @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2013 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptFunctionCall.h" + +#include "JSCInlines.h" +#include "JSLock.h" +#include "ScriptValue.h" +#include <wtf/text/WTFString.h> + +using namespace JSC; + +namespace Deprecated { + +void ScriptCallArgumentHandler::appendArgument(const Deprecated::ScriptObject& argument) +{ + if (argument.scriptState() != m_exec) { + ASSERT_NOT_REACHED(); + return; + } + m_arguments.append(argument.jsObject()); +} + +void ScriptCallArgumentHandler::appendArgument(const Deprecated::ScriptValue& argument) +{ + m_arguments.append(argument.jsValue()); +} + +void ScriptCallArgumentHandler::appendArgument(const String& argument) +{ + JSLockHolder lock(m_exec); + m_arguments.append(jsString(m_exec, argument)); +} + +void ScriptCallArgumentHandler::appendArgument(const char* argument) +{ + JSLockHolder lock(m_exec); + m_arguments.append(jsString(m_exec, String(argument))); +} + +void ScriptCallArgumentHandler::appendArgument(JSValue argument) +{ + m_arguments.append(argument); +} + +void ScriptCallArgumentHandler::appendArgument(long argument) +{ + JSLockHolder lock(m_exec); + m_arguments.append(jsNumber(argument)); +} + +void ScriptCallArgumentHandler::appendArgument(long long argument) +{ + JSLockHolder lock(m_exec); + m_arguments.append(jsNumber(argument)); +} + +void ScriptCallArgumentHandler::appendArgument(unsigned int argument) +{ + JSLockHolder lock(m_exec); + m_arguments.append(jsNumber(argument)); +} + +void ScriptCallArgumentHandler::appendArgument(unsigned long argument) +{ + JSLockHolder lock(m_exec); + m_arguments.append(jsNumber(argument)); +} + +void ScriptCallArgumentHandler::appendArgument(int argument) +{ + JSLockHolder lock(m_exec); + m_arguments.append(jsNumber(argument)); +} + +void ScriptCallArgumentHandler::appendArgument(bool argument) +{ + m_arguments.append(jsBoolean(argument)); +} + +ScriptFunctionCall::ScriptFunctionCall(const Deprecated::ScriptObject& thisObject, const String& name, ScriptFunctionCallHandler callHandler) + : ScriptCallArgumentHandler(thisObject.scriptState()) + , m_callHandler(callHandler) + , m_thisObject(thisObject) + , m_name(name) +{ +} + +Deprecated::ScriptValue ScriptFunctionCall::call(bool& hadException) +{ + JSObject* thisObject = m_thisObject.jsObject(); + + JSLockHolder lock(m_exec); + + JSValue function = thisObject->get(m_exec, Identifier::fromString(m_exec, m_name)); + if (m_exec->hadException()) { + hadException = true; + return Deprecated::ScriptValue(); + } + + CallData callData; + CallType callType = getCallData(function, callData); + if (callType == CallTypeNone) + return Deprecated::ScriptValue(); + + JSValue result; + NakedPtr<Exception> exception; + if (m_callHandler) + result = m_callHandler(m_exec, function, callType, callData, thisObject, m_arguments, exception); + else + result = JSC::call(m_exec, function, callType, callData, thisObject, m_arguments, exception); + + if (exception) { + // Do not treat a terminated execution exception as having an exception. Just treat it as an empty result. + hadException = !isTerminatedExecutionException(exception); + return Deprecated::ScriptValue(); + } + + return Deprecated::ScriptValue(m_exec->vm(), result); +} + +Deprecated::ScriptValue ScriptFunctionCall::call() +{ + bool hadException = false; + return call(hadException); +} + +} // namespace Deprecated diff --git a/Source/JavaScriptCore/bindings/ScriptFunctionCall.h b/Source/JavaScriptCore/bindings/ScriptFunctionCall.h new file mode 100644 index 000000000..25cdfb214 --- /dev/null +++ b/Source/JavaScriptCore/bindings/ScriptFunctionCall.h @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2013 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScriptFunctionCall_h +#define ScriptFunctionCall_h + +#include "ArgList.h" +#include "ScriptObject.h" +#include <wtf/text/WTFString.h> + +namespace JSC { +class JSValue; +} + +namespace Deprecated { + +class JS_EXPORT_PRIVATE ScriptCallArgumentHandler { +public: + ScriptCallArgumentHandler(JSC::ExecState* state) : m_exec(state) { } + + void appendArgument(const ScriptObject&); + void appendArgument(const ScriptValue&); + void appendArgument(const char*); + void appendArgument(const String&); + void appendArgument(JSC::JSValue); + void appendArgument(long); + void appendArgument(long long); + void appendArgument(unsigned int); + void appendArgument(unsigned long); + void appendArgument(int); + void appendArgument(bool); + +protected: + JSC::MarkedArgumentBuffer m_arguments; + JSC::ExecState* m_exec; + +private: + // MarkedArgumentBuffer must be stack allocated, so prevent heap + // alloc of ScriptFunctionCall as well. + void* operator new(size_t) { ASSERT_NOT_REACHED(); return reinterpret_cast<void*>(0xbadbeef); } + void* operator new[](size_t) { ASSERT_NOT_REACHED(); return reinterpret_cast<void*>(0xbadbeef); } +}; + +class JS_EXPORT_PRIVATE ScriptFunctionCall : public ScriptCallArgumentHandler { +public: + typedef JSC::JSValue (*ScriptFunctionCallHandler)(JSC::ExecState* exec, JSC::JSValue functionObject, JSC::CallType callType, const JSC::CallData& callData, JSC::JSValue thisValue, const JSC::ArgList& args, NakedPtr<JSC::Exception>&); + ScriptFunctionCall(const ScriptObject& thisObject, const String& name, ScriptFunctionCallHandler handler = nullptr); + ScriptValue call(bool& hadException); + ScriptValue call(); + +protected: + ScriptFunctionCallHandler m_callHandler; + ScriptObject m_thisObject; + String m_name; +}; + +} // namespace Deprecated + +#endif // ScriptFunctionCall diff --git a/Source/JavaScriptCore/bindings/ScriptObject.cpp b/Source/JavaScriptCore/bindings/ScriptObject.cpp new file mode 100644 index 000000000..70422e282 --- /dev/null +++ b/Source/JavaScriptCore/bindings/ScriptObject.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2013 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptObject.h" + +#include "JSCInlines.h" + +using namespace JSC; + +namespace Deprecated { + +ScriptObject::ScriptObject(ExecState* scriptState, JSObject* object) + : ScriptValue(scriptState->vm(), object) + , m_scriptState(scriptState) +{ +} + +ScriptObject::ScriptObject(ExecState* scriptState, const ScriptValue& scriptValue) + : ScriptValue(scriptState->vm(), scriptValue.jsValue()) + , m_scriptState(scriptState) +{ +} + +} // namespace Deprecated diff --git a/Source/JavaScriptCore/bindings/ScriptObject.h b/Source/JavaScriptCore/bindings/ScriptObject.h new file mode 100644 index 000000000..8f7b0dcdd --- /dev/null +++ b/Source/JavaScriptCore/bindings/ScriptObject.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2013 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScriptObject_h +#define ScriptObject_h + +#include "JSObject.h" +#include "ScriptValue.h" + +namespace Deprecated { + +class ScriptObject : public ScriptValue { +public: + JS_EXPORT_PRIVATE ScriptObject(JSC::ExecState*, JSC::JSObject*); + JS_EXPORT_PRIVATE ScriptObject(JSC::ExecState*, const ScriptValue&); + ScriptObject() : m_scriptState(nullptr) { } + + JSC::JSObject* jsObject() const { return asObject(jsValue()); } + JSC::ExecState* scriptState() const { return m_scriptState; } + +protected: + JSC::ExecState* m_scriptState; +}; + +} // namespace Deprecated + +#endif // ScriptObject_h diff --git a/Source/JavaScriptCore/bindings/ScriptValue.cpp b/Source/JavaScriptCore/bindings/ScriptValue.cpp new file mode 100644 index 000000000..3e560dcc3 --- /dev/null +++ b/Source/JavaScriptCore/bindings/ScriptValue.cpp @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2006, 2007, 2008, 2013 Apple Inc. All rights reserved. + * Copyright (c) 2011 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptValue.h" + +#include "APICast.h" +#include "InspectorValues.h" +#include "JSLock.h" +#include "StructureInlines.h" + +using namespace JSC; +using namespace Inspector; + +namespace Deprecated { + +ScriptValue::~ScriptValue() +{ +} + +bool ScriptValue::getString(ExecState* scriptState, String& result) const +{ + if (!m_value) + return false; + JSLockHolder lock(scriptState); + if (!m_value.get().getString(scriptState, result)) + return false; + return true; +} + +String ScriptValue::toString(ExecState* scriptState) const +{ + String result = m_value.get().toString(scriptState)->value(scriptState); + // Handle the case where an exception is thrown as part of invoking toString on the object. + if (scriptState->hadException()) + scriptState->clearException(); + return result; +} + +bool ScriptValue::isEqual(ExecState* scriptState, const ScriptValue& anotherValue) const +{ + if (hasNoValue()) + return anotherValue.hasNoValue(); + return JSValueIsEqual(toRef(scriptState), toRef(scriptState, jsValue()), toRef(scriptState, anotherValue.jsValue()), nullptr); +} + +bool ScriptValue::isNull() const +{ + if (!m_value) + return false; + return m_value.get().isNull(); +} + +bool ScriptValue::isUndefined() const +{ + if (!m_value) + return false; + return m_value.get().isUndefined(); +} + +bool ScriptValue::isObject() const +{ + if (!m_value) + return false; + return m_value.get().isObject(); +} + +bool ScriptValue::isFunction() const +{ + CallData callData; + return getCallData(m_value.get(), callData) != CallTypeNone; +} + +static RefPtr<InspectorValue> jsToInspectorValue(ExecState* scriptState, JSValue value, int maxDepth) +{ + if (!value) { + ASSERT_NOT_REACHED(); + return nullptr; + } + + if (!maxDepth) + return nullptr; + + maxDepth--; + + if (value.isNull() || value.isUndefined()) + return InspectorValue::null(); + if (value.isBoolean()) + return InspectorBasicValue::create(value.asBoolean()); + if (value.isNumber() && value.isDouble()) + return InspectorBasicValue::create(value.asNumber()); + if (value.isNumber() && value.isMachineInt()) + return InspectorBasicValue::create(static_cast<int>(value.asMachineInt())); + if (value.isString()) + return InspectorString::create(value.getString(scriptState)); + + if (value.isObject()) { + if (isJSArray(value)) { + Ref<InspectorArray> inspectorArray = InspectorArray::create(); + JSArray* array = asArray(value); + unsigned length = array->length(); + for (unsigned i = 0; i < length; i++) { + JSValue element = array->getIndex(scriptState, i); + RefPtr<InspectorValue> elementValue = jsToInspectorValue(scriptState, element, maxDepth); + if (!elementValue) + return nullptr; + inspectorArray->pushValue(WTFMove(elementValue)); + } + return WTFMove(inspectorArray); + } + Ref<InspectorObject> inspectorObject = InspectorObject::create(); + JSObject* object = value.getObject(); + PropertyNameArray propertyNames(scriptState, PropertyNameMode::Strings); + object->methodTable()->getOwnPropertyNames(object, scriptState, propertyNames, EnumerationMode()); + for (size_t i = 0; i < propertyNames.size(); i++) { + const Identifier& name = propertyNames[i]; + JSValue propertyValue = object->get(scriptState, name); + RefPtr<InspectorValue> inspectorValue = jsToInspectorValue(scriptState, propertyValue, maxDepth); + if (!inspectorValue) + return nullptr; + inspectorObject->setValue(name.string(), WTFMove(inspectorValue)); + } + return WTFMove(inspectorObject); + } + + ASSERT_NOT_REACHED(); + return nullptr; +} + +RefPtr<InspectorValue> ScriptValue::toInspectorValue(ExecState* scriptState) const +{ + JSLockHolder holder(scriptState); + return jsToInspectorValue(scriptState, m_value.get(), InspectorValue::maxDepth); +} + +} // namespace Deprecated diff --git a/Source/JavaScriptCore/bindings/ScriptValue.h b/Source/JavaScriptCore/bindings/ScriptValue.h new file mode 100644 index 000000000..78a2ee9a3 --- /dev/null +++ b/Source/JavaScriptCore/bindings/ScriptValue.h @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2013 Apple Inc. All rights reserved. + * Copyright (c) 2008, 2011 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScriptValue_h +#define ScriptValue_h + +#include "JSCJSValue.h" +#include "JSCJSValueInlines.h" +#include "Operations.h" +#include "Strong.h" +#include "StrongInlines.h" +#include <wtf/PassRefPtr.h> +#include <wtf/text/WTFString.h> + +namespace Inspector { +class InspectorValue; +} + +namespace Deprecated { + +class JS_EXPORT_PRIVATE ScriptValue { +public: + ScriptValue() { } + ScriptValue(JSC::VM& vm, JSC::JSValue value) : m_value(vm, value) { } + virtual ~ScriptValue(); + + operator JSC::JSValue() const { return jsValue(); } + JSC::JSValue jsValue() const { return m_value.get(); } + bool getString(JSC::ExecState*, String& result) const; + String toString(JSC::ExecState*) const; + bool isEqual(JSC::ExecState*, const ScriptValue&) const; + bool isNull() const; + bool isUndefined() const; + bool isObject() const; + bool isFunction() const; + bool hasNoValue() const { return !m_value; } + + void clear() { m_value.clear(); } + + bool operator==(const ScriptValue& other) const { return m_value == other.m_value; } + + RefPtr<Inspector::InspectorValue> toInspectorValue(JSC::ExecState*) const; + +private: + JSC::Strong<JSC::Unknown> m_value; +}; + +} // namespace Deprecated + +#endif // ScriptValue_h |