summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/bindings
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/JavaScriptCore/bindings
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/JavaScriptCore/bindings')
-rw-r--r--Source/JavaScriptCore/bindings/ScriptFunctionCall.cpp49
-rw-r--r--Source/JavaScriptCore/bindings/ScriptFunctionCall.h13
-rw-r--r--Source/JavaScriptCore/bindings/ScriptObject.cpp2
-rw-r--r--Source/JavaScriptCore/bindings/ScriptObject.h13
-rw-r--r--Source/JavaScriptCore/bindings/ScriptValue.cpp143
-rw-r--r--Source/JavaScriptCore/bindings/ScriptValue.h16
6 files changed, 117 insertions, 119 deletions
diff --git a/Source/JavaScriptCore/bindings/ScriptFunctionCall.cpp b/Source/JavaScriptCore/bindings/ScriptFunctionCall.cpp
index f2647da29..18d07df7e 100644
--- a/Source/JavaScriptCore/bindings/ScriptFunctionCall.cpp
+++ b/Source/JavaScriptCore/bindings/ScriptFunctionCall.cpp
@@ -32,6 +32,7 @@
#include "config.h"
#include "ScriptFunctionCall.h"
+#include "JSCInlines.h"
#include "JSLock.h"
#include "ScriptValue.h"
#include <wtf/text/WTFString.h>
@@ -40,20 +41,6 @@ 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);
@@ -114,40 +101,44 @@ ScriptFunctionCall::ScriptFunctionCall(const Deprecated::ScriptObject& thisObjec
{
}
-Deprecated::ScriptValue ScriptFunctionCall::call(bool& hadException)
+JSValue ScriptFunctionCall::call(bool& hadException)
{
JSObject* thisObject = m_thisObject.jsObject();
- JSLockHolder lock(m_exec);
+ VM& vm = m_exec->vm();
+ JSLockHolder lock(vm);
+ auto scope = DECLARE_THROW_SCOPE(vm);
- JSValue function = thisObject->get(m_exec, Identifier(m_exec, m_name));
- if (m_exec->hadException()) {
+ JSValue function = thisObject->get(m_exec, Identifier::fromString(m_exec, m_name));
+ if (UNLIKELY(scope.exception())) {
hadException = true;
- return Deprecated::ScriptValue();
+ return { };
}
CallData callData;
CallType callType = getCallData(function, callData);
- if (callType == CallTypeNone)
- return Deprecated::ScriptValue();
+ if (callType == CallType::None)
+ return { };
JSValue result;
+ NakedPtr<Exception> exception;
if (m_callHandler)
- result = m_callHandler(m_exec, function, callType, callData, thisObject, m_arguments);
+ result = m_callHandler(m_exec, function, callType, callData, thisObject, m_arguments, exception);
else
- result = JSC::call(m_exec, function, callType, callData, thisObject, m_arguments);
+ result = JSC::call(m_exec, function, callType, callData, thisObject, m_arguments, exception);
- if (m_exec->hadException()) {
- hadException = true;
- return Deprecated::ScriptValue();
+ if (exception) {
+ // Do not treat a terminated execution exception as having an exception. Just treat it as an empty result.
+ hadException = !isTerminatedExecutionException(vm, exception);
+ return { };
}
- return Deprecated::ScriptValue(m_exec->vm(), result);
+ return result;
}
-Deprecated::ScriptValue ScriptFunctionCall::call()
+JSC::JSValue ScriptFunctionCall::call()
{
- bool hadException = false;
+ bool hadException;
return call(hadException);
}
diff --git a/Source/JavaScriptCore/bindings/ScriptFunctionCall.h b/Source/JavaScriptCore/bindings/ScriptFunctionCall.h
index 04b2afe07..6978414e4 100644
--- a/Source/JavaScriptCore/bindings/ScriptFunctionCall.h
+++ b/Source/JavaScriptCore/bindings/ScriptFunctionCall.h
@@ -29,8 +29,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef ScriptFunctionCall_h
-#define ScriptFunctionCall_h
+#pragma once
#include "ArgList.h"
#include "ScriptObject.h"
@@ -46,8 +45,6 @@ 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);
@@ -71,10 +68,10 @@ private:
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);
+ 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();
+ JSC::JSValue call(bool& hadException);
+ JSC::JSValue call();
protected:
ScriptFunctionCallHandler m_callHandler;
@@ -83,5 +80,3 @@ protected:
};
} // namespace Deprecated
-
-#endif // ScriptFunctionCall
diff --git a/Source/JavaScriptCore/bindings/ScriptObject.cpp b/Source/JavaScriptCore/bindings/ScriptObject.cpp
index ccf7af28f..70422e282 100644
--- a/Source/JavaScriptCore/bindings/ScriptObject.cpp
+++ b/Source/JavaScriptCore/bindings/ScriptObject.cpp
@@ -32,6 +32,8 @@
#include "config.h"
#include "ScriptObject.h"
+#include "JSCInlines.h"
+
using namespace JSC;
namespace Deprecated {
diff --git a/Source/JavaScriptCore/bindings/ScriptObject.h b/Source/JavaScriptCore/bindings/ScriptObject.h
index 8f7b0dcdd..baa1ea8e0 100644
--- a/Source/JavaScriptCore/bindings/ScriptObject.h
+++ b/Source/JavaScriptCore/bindings/ScriptObject.h
@@ -29,8 +29,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef ScriptObject_h
-#define ScriptObject_h
+#pragma once
#include "JSObject.h"
#include "ScriptValue.h"
@@ -41,15 +40,15 @@ 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) { }
+ ScriptObject() { }
+
+ operator JSC::JSObject*() const { return jsObject(); }
JSC::JSObject* jsObject() const { return asObject(jsValue()); }
JSC::ExecState* scriptState() const { return m_scriptState; }
-protected:
- JSC::ExecState* m_scriptState;
+private:
+ JSC::ExecState* m_scriptState { nullptr };
};
} // namespace Deprecated
-
-#endif // ScriptObject_h
diff --git a/Source/JavaScriptCore/bindings/ScriptValue.cpp b/Source/JavaScriptCore/bindings/ScriptValue.cpp
index c72ab4634..2a94f3b6e 100644
--- a/Source/JavaScriptCore/bindings/ScriptValue.cpp
+++ b/Source/JavaScriptCore/bindings/ScriptValue.cpp
@@ -11,7 +11,7 @@
* 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 Computer, Inc. ("Apple") nor the names of
+ * 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.
*
@@ -32,11 +32,77 @@
#include "APICast.h"
#include "InspectorValues.h"
+#include "JSCInlines.h"
#include "JSLock.h"
using namespace JSC;
using namespace Inspector;
+namespace Inspector {
+
+static RefPtr<InspectorValue> jsToInspectorValue(ExecState& scriptState, JSValue value, int maxDepth)
+{
+ if (!value) {
+ ASSERT_NOT_REACHED();
+ return nullptr;
+ }
+
+ if (!maxDepth)
+ return nullptr;
+
+ maxDepth--;
+
+ if (value.isUndefinedOrNull())
+ return InspectorValue::null();
+ if (value.isBoolean())
+ return InspectorValue::create(value.asBoolean());
+ if (value.isNumber() && value.isDouble())
+ return InspectorValue::create(value.asNumber());
+ if (value.isNumber() && value.isAnyInt())
+ return InspectorValue::create(static_cast<int>(value.asAnyInt()));
+ if (value.isString())
+ return InspectorValue::create(asString(value)->value(&scriptState));
+
+ if (value.isObject()) {
+ if (isJSArray(value)) {
+ auto inspectorArray = InspectorArray::create();
+ auto& array = *asArray(value);
+ unsigned length = array.length();
+ for (unsigned i = 0; i < length; i++) {
+ auto elementValue = jsToInspectorValue(scriptState, array.getIndex(&scriptState, i), maxDepth);
+ if (!elementValue)
+ return nullptr;
+ inspectorArray->pushValue(WTFMove(elementValue));
+ }
+ return WTFMove(inspectorArray);
+ }
+ auto inspectorObject = InspectorObject::create();
+ auto& object = *value.getObject();
+ PropertyNameArray propertyNames(&scriptState, PropertyNameMode::Strings);
+ object.methodTable()->getOwnPropertyNames(&object, &scriptState, propertyNames, EnumerationMode());
+ for (auto& name : propertyNames) {
+ auto inspectorValue = jsToInspectorValue(scriptState, object.get(&scriptState, name), maxDepth);
+ if (!inspectorValue)
+ return nullptr;
+ inspectorObject->setValue(name.string(), WTFMove(inspectorValue));
+ }
+ return WTFMove(inspectorObject);
+ }
+
+ ASSERT_NOT_REACHED();
+ return nullptr;
+}
+
+RefPtr<InspectorValue> toInspectorValue(ExecState& state, JSValue value)
+{
+ // FIXME: Maybe we should move the JSLockHolder stuff to the callers since this function takes a JSValue directly.
+ // Doing the locking here made sense when we were trying to abstract the difference between multiple JavaScript engines.
+ JSLockHolder holder(&state);
+ return jsToInspectorValue(state, value, InspectorValue::maxDepth);
+}
+
+} // namespace Inspector
+
namespace Deprecated {
ScriptValue::~ScriptValue()
@@ -55,10 +121,13 @@ bool ScriptValue::getString(ExecState* scriptState, String& result) const
String ScriptValue::toString(ExecState* scriptState) const
{
- String result = m_value.get().toString(scriptState)->value(scriptState);
+ VM& vm = scriptState->vm();
+ auto scope = DECLARE_CATCH_SCOPE(vm);
+
+ String result = m_value.get().toWTFString(scriptState);
// Handle the case where an exception is thrown as part of invoking toString on the object.
- if (scriptState->hadException())
- scriptState->clearException();
+ if (UNLIKELY(scope.exception()))
+ scope.clearException();
return result;
}
@@ -66,7 +135,7 @@ bool ScriptValue::isEqual(ExecState* scriptState, const ScriptValue& anotherValu
{
if (hasNoValue())
return anotherValue.hasNoValue();
- return JSValueIsEqual(toRef(scriptState), toRef(scriptState, jsValue()), toRef(scriptState, anotherValue.jsValue()), nullptr);
+ return JSValueIsStrictEqual(toRef(scriptState), toRef(scriptState, jsValue()), toRef(scriptState, anotherValue.jsValue()));
}
bool ScriptValue::isNull() const
@@ -93,71 +162,13 @@ bool ScriptValue::isObject() const
bool ScriptValue::isFunction() const
{
CallData callData;
- return getCallData(m_value.get(), callData) != CallTypeNone;
-}
-
-#if ENABLE(INSPECTOR)
-static PassRefPtr<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())
- return InspectorBasicValue::create(value.asNumber());
- if (value.isString()) {
- String s = value.getString(scriptState);
- return InspectorString::create(String(s.deprecatedCharacters(), s.length()));
- }
-
- if (value.isObject()) {
- if (isJSArray(value)) {
- RefPtr<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(elementValue);
- }
- return inspectorArray;
- }
- RefPtr<InspectorObject> inspectorObject = InspectorObject::create();
- JSObject* object = value.getObject();
- PropertyNameArray propertyNames(scriptState);
- object->methodTable()->getOwnPropertyNames(object, scriptState, propertyNames, ExcludeDontEnumProperties);
- 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(String(name.deprecatedCharacters(), name.length()), inspectorValue);
- }
- return inspectorObject;
- }
-
- ASSERT_NOT_REACHED();
- return nullptr;
+ return getCallData(m_value.get(), callData) != CallType::None;
}
-PassRefPtr<InspectorValue> ScriptValue::toInspectorValue(ExecState* scriptState) const
+RefPtr<InspectorValue> ScriptValue::toInspectorValue(ExecState* scriptState) const
{
JSLockHolder holder(scriptState);
- return jsToInspectorValue(scriptState, m_value.get(), InspectorValue::maxDepth);
+ return jsToInspectorValue(*scriptState, m_value.get(), InspectorValue::maxDepth);
}
-#endif // ENABLE(INSPECTOR)
} // namespace Deprecated
diff --git a/Source/JavaScriptCore/bindings/ScriptValue.h b/Source/JavaScriptCore/bindings/ScriptValue.h
index d5fade90b..7eb50725d 100644
--- a/Source/JavaScriptCore/bindings/ScriptValue.h
+++ b/Source/JavaScriptCore/bindings/ScriptValue.h
@@ -29,18 +29,21 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef ScriptValue_h
-#define ScriptValue_h
+#pragma once
#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;
+
+JS_EXPORT_PRIVATE RefPtr<InspectorValue> toInspectorValue(JSC::ExecState&, JSC::JSValue);
+
}
namespace Deprecated {
@@ -51,6 +54,7 @@ public:
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;
@@ -65,14 +69,10 @@ public:
bool operator==(const ScriptValue& other) const { return m_value == other.m_value; }
-#if ENABLE(INSPECTOR)
- PassRefPtr<Inspector::InspectorValue> toInspectorValue(JSC::ExecState*) const;
-#endif
+ RefPtr<Inspector::InspectorValue> toInspectorValue(JSC::ExecState*) const;
private:
JSC::Strong<JSC::Unknown> m_value;
};
} // namespace Deprecated
-
-#endif // ScriptValue_h