summaryrefslogtreecommitdiffstats
path: root/JavaScriptCore/API
diff options
context:
space:
mode:
Diffstat (limited to 'JavaScriptCore/API')
-rw-r--r--JavaScriptCore/API/JSCallbackConstructor.cpp14
-rw-r--r--JavaScriptCore/API/JSCallbackFunction.cpp7
-rw-r--r--JavaScriptCore/API/JSCallbackFunction.h2
-rw-r--r--JavaScriptCore/API/JSCallbackObject.h4
-rw-r--r--JavaScriptCore/API/JSCallbackObjectFunctions.h48
-rw-r--r--JavaScriptCore/API/JSObjectRef.cpp7
6 files changed, 43 insertions, 39 deletions
diff --git a/JavaScriptCore/API/JSCallbackConstructor.cpp b/JavaScriptCore/API/JSCallbackConstructor.cpp
index 2948932..66c6b88 100644
--- a/JavaScriptCore/API/JSCallbackConstructor.cpp
+++ b/JavaScriptCore/API/JSCallbackConstructor.cpp
@@ -28,6 +28,7 @@
#include "APIShims.h"
#include "APICast.h"
+#include <runtime/Error.h>
#include <runtime/JSGlobalObject.h>
#include <runtime/JSLock.h>
#include <runtime/ObjectPrototype.h>
@@ -52,17 +53,18 @@ JSCallbackConstructor::~JSCallbackConstructor()
JSClassRelease(m_class);
}
-static JSObject* constructJSCallback(ExecState* exec, JSObject* constructor, const ArgList& args)
+static EncodedJSValue JSC_HOST_CALL constructJSCallback(ExecState* exec)
{
+ JSObject* constructor = exec->callee();
JSContextRef ctx = toRef(exec);
JSObjectRef constructorRef = toRef(constructor);
JSObjectCallAsConstructorCallback callback = static_cast<JSCallbackConstructor*>(constructor)->callback();
if (callback) {
- int argumentCount = static_cast<int>(args.size());
+ int argumentCount = static_cast<int>(exec->argumentCount());
Vector<JSValueRef, 16> arguments(argumentCount);
for (int i = 0; i < argumentCount; i++)
- arguments[i] = toRef(exec, args.at(i));
+ arguments[i] = toRef(exec, exec->argument(i));
JSValueRef exception = 0;
JSObjectRef result;
@@ -71,11 +73,11 @@ static JSObject* constructJSCallback(ExecState* exec, JSObject* constructor, con
result = callback(ctx, constructorRef, argumentCount, arguments.data(), &exception);
}
if (exception)
- exec->setException(toJS(exec, exception));
- return toJS(result);
+ throwError(exec, toJS(exec, exception));
+ return JSValue::encode(toJS(result));
}
- return toJS(JSObjectMake(ctx, static_cast<JSCallbackConstructor*>(constructor)->classRef(), 0));
+ return JSValue::encode(toJS(JSObjectMake(ctx, static_cast<JSCallbackConstructor*>(constructor)->classRef(), 0)));
}
ConstructType JSCallbackConstructor::getConstructData(ConstructData& constructData)
diff --git a/JavaScriptCore/API/JSCallbackFunction.cpp b/JavaScriptCore/API/JSCallbackFunction.cpp
index 9db9983..c488aa6 100644
--- a/JavaScriptCore/API/JSCallbackFunction.cpp
+++ b/JavaScriptCore/API/JSCallbackFunction.cpp
@@ -29,6 +29,7 @@
#include "APIShims.h"
#include "APICast.h"
#include "CodeBlock.h"
+#include "ExceptionHelpers.h"
#include "JSFunction.h"
#include "FunctionPrototype.h"
#include <runtime/JSGlobalObject.h>
@@ -47,7 +48,7 @@ JSCallbackFunction::JSCallbackFunction(ExecState* exec, JSGlobalObject* globalOb
{
}
-JSValue JSCallbackFunction::call(ExecState* exec)
+EncodedJSValue JSCallbackFunction::call(ExecState* exec)
{
JSContextRef execRef = toRef(exec);
JSObjectRef functionRef = toRef(exec->callee());
@@ -65,9 +66,9 @@ JSValue JSCallbackFunction::call(ExecState* exec)
result = static_cast<JSCallbackFunction*>(toJS(functionRef))->m_callback(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), &exception);
}
if (exception)
- exec->setException(toJS(exec, exception));
+ throwError(exec, toJS(exec, exception));
- return toJS(exec, result);
+ return JSValue::encode(toJS(exec, result));
}
CallType JSCallbackFunction::getCallData(CallData& callData)
diff --git a/JavaScriptCore/API/JSCallbackFunction.h b/JavaScriptCore/API/JSCallbackFunction.h
index 3940e7d..b119b97 100644
--- a/JavaScriptCore/API/JSCallbackFunction.h
+++ b/JavaScriptCore/API/JSCallbackFunction.h
@@ -48,7 +48,7 @@ private:
virtual CallType getCallData(CallData&);
virtual const ClassInfo* classInfo() const { return &info; }
- static JSValue JSC_HOST_CALL call(ExecState*);
+ static EncodedJSValue JSC_HOST_CALL call(ExecState*);
JSObjectCallAsFunctionCallback m_callback;
};
diff --git a/JavaScriptCore/API/JSCallbackObject.h b/JavaScriptCore/API/JSCallbackObject.h
index 7216ac5..dfb9fa2 100644
--- a/JavaScriptCore/API/JSCallbackObject.h
+++ b/JavaScriptCore/API/JSCallbackObject.h
@@ -182,8 +182,8 @@ private:
static JSCallbackObject* asCallbackObject(JSValue);
- static JSValue JSC_HOST_CALL call(ExecState*);
- static JSObject* construct(ExecState*, JSObject* constructor, const ArgList&);
+ static EncodedJSValue JSC_HOST_CALL call(ExecState*);
+ static EncodedJSValue JSC_HOST_CALL construct(ExecState*);
static JSValue staticValueGetter(ExecState*, JSValue, const Identifier&);
static JSValue staticFunctionGetter(ExecState*, JSValue, const Identifier&);
diff --git a/JavaScriptCore/API/JSCallbackObjectFunctions.h b/JavaScriptCore/API/JSCallbackObjectFunctions.h
index ef1efd2..3a15bbe 100644
--- a/JavaScriptCore/API/JSCallbackObjectFunctions.h
+++ b/JavaScriptCore/API/JSCallbackObjectFunctions.h
@@ -27,6 +27,7 @@
#include "APIShims.h"
#include "APICast.h"
#include "Error.h"
+#include "ExceptionHelpers.h"
#include "JSCallbackFunction.h"
#include "JSClassRef.h"
#include "JSFunction.h"
@@ -134,7 +135,7 @@ bool JSCallbackObject<Base>::getOwnPropertySlot(ExecState* exec, const Identifie
value = getProperty(ctx, thisRef, propertyNameRef.get(), &exception);
}
if (exception) {
- exec->setException(toJS(exec, exception));
+ throwError(exec, toJS(exec, exception));
slot.setValue(jsUndefined());
return true;
}
@@ -206,7 +207,7 @@ void JSCallbackObject<Base>::put(ExecState* exec, const Identifier& propertyName
result = setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, &exception);
}
if (exception)
- exec->setException(toJS(exec, exception));
+ throwError(exec, toJS(exec, exception));
if (result || exception)
return;
}
@@ -225,11 +226,11 @@ void JSCallbackObject<Base>::put(ExecState* exec, const Identifier& propertyName
result = setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, &exception);
}
if (exception)
- exec->setException(toJS(exec, exception));
+ throwError(exec, toJS(exec, exception));
if (result || exception)
return;
} else
- throwError(exec, ReferenceError, "Attempt to set a property that is not settable.");
+ throwError(exec, createReferenceError(exec, "Attempt to set a property that is not settable."));
}
}
@@ -264,7 +265,7 @@ bool JSCallbackObject<Base>::deleteProperty(ExecState* exec, const Identifier& p
result = deleteProperty(ctx, thisRef, propertyNameRef.get(), &exception);
}
if (exception)
- exec->setException(toJS(exec, exception));
+ throwError(exec, toJS(exec, exception));
if (result || exception)
return true;
}
@@ -308,17 +309,18 @@ ConstructType JSCallbackObject<Base>::getConstructData(ConstructData& constructD
}
template <class Base>
-JSObject* JSCallbackObject<Base>::construct(ExecState* exec, JSObject* constructor, const ArgList& args)
+EncodedJSValue JSCallbackObject<Base>::construct(ExecState* exec)
{
+ JSObject* constructor = exec->callee();
JSContextRef execRef = toRef(exec);
JSObjectRef constructorRef = toRef(constructor);
for (JSClassRef jsClass = static_cast<JSCallbackObject<Base>*>(constructor)->classRef(); jsClass; jsClass = jsClass->parentClass) {
if (JSObjectCallAsConstructorCallback callAsConstructor = jsClass->callAsConstructor) {
- int argumentCount = static_cast<int>(args.size());
+ int argumentCount = static_cast<int>(exec->argumentCount());
Vector<JSValueRef, 16> arguments(argumentCount);
for (int i = 0; i < argumentCount; i++)
- arguments[i] = toRef(exec, args.at(i));
+ arguments[i] = toRef(exec, exec->argument(i));
JSValueRef exception = 0;
JSObject* result;
{
@@ -326,13 +328,13 @@ JSObject* JSCallbackObject<Base>::construct(ExecState* exec, JSObject* construct
result = toJS(callAsConstructor(execRef, constructorRef, argumentCount, arguments.data(), &exception));
}
if (exception)
- exec->setException(toJS(exec, exception));
- return result;
+ throwError(exec, toJS(exec, exception));
+ return JSValue::encode(result);
}
}
ASSERT_NOT_REACHED(); // getConstructData should prevent us from reaching here
- return 0;
+ return JSValue::encode(JSValue());
}
template <class Base>
@@ -351,7 +353,7 @@ bool JSCallbackObject<Base>::hasInstance(ExecState* exec, JSValue value, JSValue
result = hasInstance(execRef, thisRef, valueRef, &exception);
}
if (exception)
- exec->setException(toJS(exec, exception));
+ throwError(exec, toJS(exec, exception));
return result;
}
}
@@ -371,7 +373,7 @@ CallType JSCallbackObject<Base>::getCallData(CallData& callData)
}
template <class Base>
-JSValue JSCallbackObject<Base>::call(ExecState* exec)
+EncodedJSValue JSCallbackObject<Base>::call(ExecState* exec)
{
JSContextRef execRef = toRef(exec);
JSObjectRef functionRef = toRef(exec->callee());
@@ -390,13 +392,13 @@ JSValue JSCallbackObject<Base>::call(ExecState* exec)
result = toJS(exec, callAsFunction(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), &exception));
}
if (exception)
- exec->setException(toJS(exec, exception));
- return result;
+ throwError(exec, toJS(exec, exception));
+ return JSValue::encode(result);
}
}
ASSERT_NOT_REACHED(); // getCallData should prevent us from reaching here
- return JSValue();
+ return JSValue::encode(JSValue());
}
template <class Base>
@@ -457,7 +459,7 @@ double JSCallbackObject<Base>::toNumber(ExecState* exec) const
value = convertToType(ctx, thisRef, kJSTypeNumber, &exception);
}
if (exception) {
- exec->setException(toJS(exec, exception));
+ throwError(exec, toJS(exec, exception));
return 0;
}
@@ -484,7 +486,7 @@ UString JSCallbackObject<Base>::toString(ExecState* exec) const
value = convertToType(ctx, thisRef, kJSTypeString, &exception);
}
if (exception) {
- exec->setException(toJS(exec, exception));
+ throwError(exec, toJS(exec, exception));
return "";
}
if (value)
@@ -537,14 +539,14 @@ JSValue JSCallbackObject<Base>::staticValueGetter(ExecState* exec, JSValue slotB
value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), &exception);
}
if (exception) {
- exec->setException(toJS(exec, exception));
+ throwError(exec, toJS(exec, exception));
return jsUndefined();
}
if (value)
return toJS(exec, value);
}
- return throwError(exec, ReferenceError, "Static value property defined with NULL getProperty callback.");
+ return throwError(exec, createReferenceError(exec, "Static value property defined with NULL getProperty callback."));
}
template <class Base>
@@ -570,7 +572,7 @@ JSValue JSCallbackObject<Base>::staticFunctionGetter(ExecState* exec, JSValue sl
}
}
- return throwError(exec, ReferenceError, "Static function property defined with NULL callAsFunction callback.");
+ return throwError(exec, createReferenceError(exec, "Static function property defined with NULL callAsFunction callback."));
}
template <class Base>
@@ -592,14 +594,14 @@ JSValue JSCallbackObject<Base>::callbackGetter(ExecState* exec, JSValue slotBase
value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), &exception);
}
if (exception) {
- exec->setException(toJS(exec, exception));
+ throwError(exec, toJS(exec, exception));
return jsUndefined();
}
if (value)
return toJS(exec, value);
}
- return throwError(exec, ReferenceError, "hasProperty callback returned true for a property that doesn't exist.");
+ return throwError(exec, createReferenceError(exec, "hasProperty callback returned true for a property that doesn't exist."));
}
} // namespace JSC
diff --git a/JavaScriptCore/API/JSObjectRef.cpp b/JavaScriptCore/API/JSObjectRef.cpp
index 70c4e14..5e0536f 100644
--- a/JavaScriptCore/API/JSObjectRef.cpp
+++ b/JavaScriptCore/API/JSObjectRef.cpp
@@ -184,11 +184,10 @@ JSObjectRef JSObjectMakeError(JSContextRef ctx, size_t argumentCount, const JSVa
ExecState* exec = toJS(ctx);
APIEntryShim entryShim(exec);
- MarkedArgumentBuffer argList;
- for (size_t i = 0; i < argumentCount; ++i)
- argList.append(toJS(exec, arguments[i]));
+ JSValue message = argumentCount ? toJS(exec, arguments[0]) : jsUndefined();
+ Structure* errorStructure = exec->lexicalGlobalObject()->errorStructure();
+ JSObject* result = ErrorInstance::create(exec, errorStructure, message);
- JSObject* result = constructError(exec, argList);
if (exec->hadException()) {
if (exception)
*exception = toRef(exec, exec->exception());