#include "CopiedSpaceInlines.h"
#include "DateConstructor.h"
#include "ErrorConstructor.h"
+#include "Exception.h"
#include "FunctionConstructor.h"
#include "Identifier.h"
#include "InitializeThreading.h"
using namespace JSC;
+enum class ExceptionStatus {
+ DidThrow,
+ DidNotThrow
+};
+
+static ExceptionStatus handleExceptionIfNeeded(ExecState* exec, JSValueRef* returnedExceptionRef)
+{
+ if (exec->hadException()) {
+ Exception* exception = exec->exception();
+ if (returnedExceptionRef)
+ *returnedExceptionRef = toRef(exec, exception->value());
+ exec->clearException();
+#if ENABLE(REMOTE_INSPECTOR)
+ exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exception);
+#endif
+ return ExceptionStatus::DidThrow;
+ }
+ return ExceptionStatus::DidNotThrow;
+}
+
JSClassRef JSClassCreate(const JSClassDefinition* definition)
{
initializeThreading();
JSLockHolder locker(exec);
startingLineNumber = std::max(1, startingLineNumber);
- Identifier nameID = name ? name->identifier(&exec->vm()) : Identifier(exec, "anonymous");
+ Identifier nameID = name ? name->identifier(&exec->vm()) : Identifier::fromString(exec, "anonymous");
MarkedArgumentBuffer args;
for (unsigned i = 0; i < parameterCount; i++)
args.append(jsString(exec, parameterNames[i]->string()));
args.append(jsString(exec, body->string()));
- JSObject* result = constructFunction(exec, exec->lexicalGlobalObject(), args, nameID, sourceURL->string(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber), OrdinalNumber::first()));
- if (exec->hadException()) {
- JSValue exceptionValue = exec->exception();
- if (exception)
- *exception = toRef(exec, exceptionValue);
- exec->clearException();
-#if ENABLE(REMOTE_INSPECTOR)
- exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
-#endif
+ JSObject* result = constructFunction(exec, exec->lexicalGlobalObject(), args, nameID, sourceURL ? sourceURL->string() : String(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber), OrdinalNumber::first()));
+ if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow)
result = 0;
- }
return toRef(result);
}
} else
result = constructEmptyArray(exec, 0);
- if (exec->hadException()) {
- JSValue exceptionValue = exec->exception();
- if (exception)
- *exception = toRef(exec, exceptionValue);
- exec->clearException();
-#if ENABLE(REMOTE_INSPECTOR)
- exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
-#endif
+ if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow)
result = 0;
- }
return toRef(result);
}
argList.append(toJS(exec, arguments[i]));
JSObject* result = constructDate(exec, exec->lexicalGlobalObject(), argList);
- if (exec->hadException()) {
- JSValue exceptionValue = exec->exception();
- if (exception)
- *exception = toRef(exec, exceptionValue);
- exec->clearException();
-#if ENABLE(REMOTE_INSPECTOR)
- exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
-#endif
+ if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow)
result = 0;
- }
return toRef(result);
}
Structure* errorStructure = exec->lexicalGlobalObject()->errorStructure();
JSObject* result = ErrorInstance::create(exec, errorStructure, message);
- if (exec->hadException()) {
- JSValue exceptionValue = exec->exception();
- if (exception)
- *exception = toRef(exec, exceptionValue);
- exec->clearException();
-#if ENABLE(REMOTE_INSPECTOR)
- exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
-#endif
+ if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow)
result = 0;
- }
return toRef(result);
}
argList.append(toJS(exec, arguments[i]));
JSObject* result = constructRegExp(exec, exec->lexicalGlobalObject(), argList);
- if (exec->hadException()) {
- JSValue exceptionValue = exec->exception();
- if (exception)
- *exception = toRef(exec, exceptionValue);
- exec->clearException();
-#if ENABLE(REMOTE_INSPECTOR)
- exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
-#endif
+ if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow)
result = 0;
- }
return toRef(result);
}
JSObject* jsObject = toJS(object);
JSValue jsValue = toJS(exec, value);
+ if (JSProxy* proxy = jsDynamicCast<JSProxy*>(jsObject)) {
+ if (JSGlobalObject* globalObject = jsDynamicCast<JSGlobalObject*>(proxy->target())) {
+ globalObject->resetPrototype(exec->vm(), jsValue.isObject() ? jsValue : jsNull());
+ return;
+ }
+ // Someday we might use proxies for something other than JSGlobalObjects, but today is not that day.
+ RELEASE_ASSERT_NOT_REACHED();
+ }
jsObject->setPrototypeWithCycleCheck(exec, jsValue.isObject() ? jsValue : jsNull());
}
JSObject* jsObject = toJS(object);
JSValue jsValue = jsObject->get(exec, propertyName->identifier(&exec->vm()));
- if (exec->hadException()) {
- JSValue exceptionValue = exec->exception();
- if (exception)
- *exception = toRef(exec, exceptionValue);
- exec->clearException();
-#if ENABLE(REMOTE_INSPECTOR)
- exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
-#endif
- }
+ handleExceptionIfNeeded(exec, exception);
return toRef(exec, jsValue);
}
jsObject->methodTable()->put(jsObject, exec, name, jsValue, slot);
}
- if (exec->hadException()) {
- JSValue exceptionValue = exec->exception();
- if (exception)
- *exception = toRef(exec, exceptionValue);
- exec->clearException();
-#if ENABLE(REMOTE_INSPECTOR)
- exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
-#endif
- }
+ handleExceptionIfNeeded(exec, exception);
}
JSValueRef JSObjectGetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception)
JSObject* jsObject = toJS(object);
JSValue jsValue = jsObject->get(exec, propertyIndex);
- if (exec->hadException()) {
- JSValue exceptionValue = exec->exception();
- if (exception)
- *exception = toRef(exec, exceptionValue);
- exec->clearException();
-#if ENABLE(REMOTE_INSPECTOR)
- exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
-#endif
- }
+ handleExceptionIfNeeded(exec, exception);
return toRef(exec, jsValue);
}
JSValue jsValue = toJS(exec, value);
jsObject->methodTable()->putByIndex(jsObject, exec, propertyIndex, jsValue, false);
- if (exec->hadException()) {
- JSValue exceptionValue = exec->exception();
- if (exception)
- *exception = toRef(exec, exceptionValue);
- exec->clearException();
-#if ENABLE(REMOTE_INSPECTOR)
- exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
-#endif
- }
+ handleExceptionIfNeeded(exec, exception);
}
bool JSObjectDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
JSObject* jsObject = toJS(object);
bool result = jsObject->methodTable()->deleteProperty(jsObject, exec, propertyName->identifier(&exec->vm()));
- if (exec->hadException()) {
- JSValue exceptionValue = exec->exception();
- if (exception)
- *exception = toRef(exec, exceptionValue);
- exec->clearException();
-#if ENABLE(REMOTE_INSPECTOR)
- exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
-#endif
- }
+ handleExceptionIfNeeded(exec, exception);
return result;
}
JSObject* jsObject = toJS(object);
JSValue result;
Identifier name(propertyName->identifier(&exec->vm()));
+
+ // Get wrapped object if proxied
+ if (jsObject->inherits(JSProxy::info()))
+ jsObject = jsCast<JSProxy*>(jsObject)->target();
+
if (jsObject->inherits(JSCallbackObject<JSGlobalObject>::info()))
result = jsCast<JSCallbackObject<JSGlobalObject>*>(jsObject)->getPrivateProperty(name);
else if (jsObject->inherits(JSCallbackObject<JSDestructibleObject>::info()))
JSObject* jsObject = toJS(object);
JSValue jsValue = value ? toJS(exec, value) : JSValue();
Identifier name(propertyName->identifier(&exec->vm()));
+
+ // Get wrapped object if proxied
+ if (jsObject->inherits(JSProxy::info()))
+ jsObject = jsCast<JSProxy*>(jsObject)->target();
+
if (jsObject->inherits(JSCallbackObject<JSGlobalObject>::info())) {
jsCast<JSCallbackObject<JSGlobalObject>*>(jsObject)->setPrivateProperty(exec->vm(), name, jsValue);
return true;
JSLockHolder locker(exec);
JSObject* jsObject = toJS(object);
Identifier name(propertyName->identifier(&exec->vm()));
+
+ // Get wrapped object if proxied
+ if (jsObject->inherits(JSProxy::info()))
+ jsObject = jsCast<JSProxy*>(jsObject)->target();
+
if (jsObject->inherits(JSCallbackObject<JSGlobalObject>::info())) {
jsCast<JSCallbackObject<JSGlobalObject>*>(jsObject)->deletePrivateProperty(name);
return true;
return 0;
JSValueRef result = toRef(exec, call(exec, jsObject, callType, callData, jsThisObject, argList));
- if (exec->hadException()) {
- JSValue exceptionValue = exec->exception();
- if (exception)
- *exception = toRef(exec, exceptionValue);
- exec->clearException();
-#if ENABLE(REMOTE_INSPECTOR)
- exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
-#endif
+ if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow)
result = 0;
- }
return result;
}
for (size_t i = 0; i < argumentCount; i++)
argList.append(toJS(exec, arguments[i]));
JSObjectRef result = toRef(construct(exec, jsObject, constructType, constructData, argList));
- if (exec->hadException()) {
- JSValue exceptionValue = exec->exception();
- if (exception)
- *exception = toRef(exec, exceptionValue);
- exec->clearException();
-#if ENABLE(REMOTE_INSPECTOR)
- exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exceptionValue);
-#endif
+ if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow)
result = 0;
- }
return result;
}
JSObject* jsObject = toJS(object);
JSPropertyNameArrayRef propertyNames = new OpaqueJSPropertyNameArray(vm);
PropertyNameArray array(vm);
- jsObject->methodTable()->getPropertyNames(jsObject, exec, array, ExcludeDontEnumProperties);
+ jsObject->methodTable()->getPropertyNames(jsObject, exec, array, EnumerationMode());
size_t size = array.size();
propertyNames->array.reserveInitialCapacity(size);