From 32761a6cee1d0dee366b885b7b9c777e67885688 Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Sun, 10 Apr 2016 09:28:39 +0000 Subject: webkitgtk-2.4.11 --- Source/JavaScriptCore/API/JSObjectRef.cpp | 210 ++++++++++++++---------------- 1 file changed, 100 insertions(+), 110 deletions(-) (limited to 'Source/JavaScriptCore/API/JSObjectRef.cpp') diff --git a/Source/JavaScriptCore/API/JSObjectRef.cpp b/Source/JavaScriptCore/API/JSObjectRef.cpp index 78efc2461..56fe90b47 100644 --- a/Source/JavaScriptCore/API/JSObjectRef.cpp +++ b/Source/JavaScriptCore/API/JSObjectRef.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2008, 2016 Apple Inc. All rights reserved. + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. * Copyright (C) 2008 Kelvin W Sherlock (ksherlock@gmail.com) * * Redistribution and use in source and binary forms, with or without @@ -11,10 +11,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. 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 @@ -34,7 +34,6 @@ #include "CopiedSpaceInlines.h" #include "DateConstructor.h" #include "ErrorConstructor.h" -#include "Exception.h" #include "FunctionConstructor.h" #include "Identifier.h" #include "InitializeThreading.h" @@ -52,36 +51,12 @@ #include "JSValueRef.h" #include "ObjectConstructor.h" #include "ObjectPrototype.h" -#include "JSCInlines.h" +#include "Operations.h" #include "PropertyNameArray.h" #include "RegExpConstructor.h" -#if ENABLE(REMOTE_INSPECTOR) -#include "JSGlobalObjectInspectorController.h" -#endif - 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(); @@ -110,7 +85,7 @@ JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, void* data) return 0; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); if (!jsClass) return toRef(constructEmptyObject(exec)); @@ -129,7 +104,7 @@ JSObjectRef JSObjectMakeFunctionWithCallback(JSContextRef ctx, JSStringRef name, return 0; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); return toRef(JSCallbackFunction::create(exec->vm(), exec->lexicalGlobalObject(), callAsFunction, name ? name->string() : ASCIILiteral("anonymous"))); } @@ -140,7 +115,7 @@ JSObjectRef JSObjectMakeConstructor(JSContextRef ctx, JSClassRef jsClass, JSObje return 0; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSValue jsPrototype = jsClass ? jsClass->prototype(exec) : 0; if (!jsPrototype) @@ -158,19 +133,23 @@ JSObjectRef JSObjectMakeFunction(JSContextRef ctx, JSStringRef name, unsigned pa return 0; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); startingLineNumber = std::max(1, startingLineNumber); - Identifier nameID = name ? name->identifier(&exec->vm()) : Identifier::fromString(exec, "anonymous"); + Identifier nameID = name ? name->identifier(&exec->vm()) : Identifier(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 ? sourceURL->string() : String(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber), OrdinalNumber::first())); - if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow) + JSObject* result = constructFunction(exec, exec->lexicalGlobalObject(), args, nameID, sourceURL->string(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber), OrdinalNumber::first())); + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); result = 0; + } return toRef(result); } @@ -181,7 +160,7 @@ JSObjectRef JSObjectMakeArray(JSContextRef ctx, size_t argumentCount, const JSVa return 0; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSObject* result; if (argumentCount) { @@ -193,8 +172,12 @@ JSObjectRef JSObjectMakeArray(JSContextRef ctx, size_t argumentCount, const JSVa } else result = constructEmptyArray(exec, 0); - if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow) + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); result = 0; + } return toRef(result); } @@ -206,15 +189,19 @@ JSObjectRef JSObjectMakeDate(JSContextRef ctx, size_t argumentCount, const JSVal return 0; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); MarkedArgumentBuffer argList; for (size_t i = 0; i < argumentCount; ++i) argList.append(toJS(exec, arguments[i])); - JSObject* result = constructDate(exec, exec->lexicalGlobalObject(), JSValue(), argList); - if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow) + JSObject* result = constructDate(exec, exec->lexicalGlobalObject(), argList); + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); result = 0; + } return toRef(result); } @@ -226,14 +213,18 @@ JSObjectRef JSObjectMakeError(JSContextRef ctx, size_t argumentCount, const JSVa return 0; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSValue message = argumentCount ? toJS(exec, arguments[0]) : jsUndefined(); Structure* errorStructure = exec->lexicalGlobalObject()->errorStructure(); JSObject* result = ErrorInstance::create(exec, errorStructure, message); - if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow) + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); result = 0; + } return toRef(result); } @@ -245,15 +236,19 @@ JSObjectRef JSObjectMakeRegExp(JSContextRef ctx, size_t argumentCount, const JSV return 0; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); MarkedArgumentBuffer argList; for (size_t i = 0; i < argumentCount; ++i) argList.append(toJS(exec, arguments[i])); - JSObject* result = constructRegExp(exec, exec->lexicalGlobalObject(), argList); - if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow) + JSObject* result = constructRegExp(exec, exec->lexicalGlobalObject(), argList); + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); result = 0; + } return toRef(result); } @@ -265,7 +260,7 @@ JSValueRef JSObjectGetPrototype(JSContextRef ctx, JSObjectRef object) return 0; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSObject* jsObject = toJS(object); return toRef(exec, jsObject->prototype()); @@ -278,19 +273,11 @@ void JSObjectSetPrototype(JSContextRef ctx, JSObjectRef object, JSValueRef value return; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSObject* jsObject = toJS(object); JSValue jsValue = toJS(exec, value); - if (JSProxy* proxy = jsDynamicCast(jsObject)) { - if (JSGlobalObject* globalObject = jsDynamicCast(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()); } @@ -301,7 +288,7 @@ bool JSObjectHasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef prope return false; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSObject* jsObject = toJS(object); @@ -315,12 +302,16 @@ JSValueRef JSObjectGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef return 0; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSObject* jsObject = toJS(object); JSValue jsValue = jsObject->get(exec, propertyName->identifier(&exec->vm())); - handleExceptionIfNeeded(exec, exception); + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); + } return toRef(exec, jsValue); } @@ -331,7 +322,7 @@ void JSObjectSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef prope return; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSObject* jsObject = toJS(object); Identifier name(propertyName->identifier(&exec->vm())); @@ -345,7 +336,11 @@ void JSObjectSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef prope jsObject->methodTable()->put(jsObject, exec, name, jsValue, slot); } - handleExceptionIfNeeded(exec, exception); + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); + } } JSValueRef JSObjectGetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception) @@ -355,12 +350,16 @@ JSValueRef JSObjectGetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsi return 0; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSObject* jsObject = toJS(object); JSValue jsValue = jsObject->get(exec, propertyIndex); - handleExceptionIfNeeded(exec, exception); + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); + } return toRef(exec, jsValue); } @@ -372,13 +371,17 @@ void JSObjectSetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned p return; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSObject* jsObject = toJS(object); JSValue jsValue = toJS(exec, value); jsObject->methodTable()->putByIndex(jsObject, exec, propertyIndex, jsValue, false); - handleExceptionIfNeeded(exec, exception); + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); + } } bool JSObjectDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) @@ -388,23 +391,23 @@ bool JSObjectDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef pr return false; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSObject* jsObject = toJS(object); bool result = jsObject->methodTable()->deleteProperty(jsObject, exec, propertyName->identifier(&exec->vm())); - handleExceptionIfNeeded(exec, exception); + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); + } return result; } void* JSObjectGetPrivate(JSObjectRef object) { JSObject* jsObject = uncheckedToJS(object); - - // Get wrapped object if proxied - if (jsObject->inherits(JSProxy::info())) - jsObject = jsCast(jsObject)->target(); - + if (jsObject->inherits(JSCallbackObject::info())) return jsCast*>(jsObject)->getPrivate(); if (jsObject->inherits(JSCallbackObject::info())) @@ -420,11 +423,7 @@ void* JSObjectGetPrivate(JSObjectRef object) bool JSObjectSetPrivate(JSObjectRef object, void* data) { JSObject* jsObject = uncheckedToJS(object); - - // Get wrapped object if proxied - if (jsObject->inherits(JSProxy::info())) - jsObject = jsCast(jsObject)->target(); - + if (jsObject->inherits(JSCallbackObject::info())) { jsCast*>(jsObject)->setPrivate(data); return true; @@ -446,15 +445,10 @@ bool JSObjectSetPrivate(JSObjectRef object, void* data) JSValueRef JSObjectGetPrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName) { ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSObject* jsObject = toJS(object); JSValue result; Identifier name(propertyName->identifier(&exec->vm())); - - // Get wrapped object if proxied - if (jsObject->inherits(JSProxy::info())) - jsObject = jsCast(jsObject)->target(); - if (jsObject->inherits(JSCallbackObject::info())) result = jsCast*>(jsObject)->getPrivateProperty(name); else if (jsObject->inherits(JSCallbackObject::info())) @@ -469,15 +463,10 @@ JSValueRef JSObjectGetPrivateProperty(JSContextRef ctx, JSObjectRef object, JSSt bool JSObjectSetPrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value) { ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); 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(jsObject)->target(); - if (jsObject->inherits(JSCallbackObject::info())) { jsCast*>(jsObject)->setPrivateProperty(exec->vm(), name, jsValue); return true; @@ -498,14 +487,9 @@ bool JSObjectSetPrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRe bool JSObjectDeletePrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName) { ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSObject* jsObject = toJS(object); Identifier name(propertyName->identifier(&exec->vm())); - - // Get wrapped object if proxied - if (jsObject->inherits(JSProxy::info())) - jsObject = jsCast(jsObject)->target(); - if (jsObject->inherits(JSCallbackObject::info())) { jsCast*>(jsObject)->deletePrivateProperty(name); return true; @@ -523,11 +507,10 @@ bool JSObjectDeletePrivateProperty(JSContextRef ctx, JSObjectRef object, JSStrin return false; } -bool JSObjectIsFunction(JSContextRef ctx, JSObjectRef object) +bool JSObjectIsFunction(JSContextRef, JSObjectRef object) { if (!object) return false; - JSLockHolder locker(toJS(ctx)); CallData callData; JSCell* cell = toJS(object); return cell->methodTable()->getCallData(cell, callData) != CallTypeNone; @@ -536,7 +519,7 @@ bool JSObjectIsFunction(JSContextRef ctx, JSObjectRef object) JSValueRef JSObjectCallAsFunction(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); if (!object) return 0; @@ -556,9 +539,13 @@ JSValueRef JSObjectCallAsFunction(JSContextRef ctx, JSObjectRef object, JSObject if (callType == CallTypeNone) return 0; - JSValueRef result = toRef(exec, profiledCall(exec, ProfilingReason::API, jsObject, callType, callData, jsThisObject, argList)); - if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow) + JSValueRef result = toRef(exec, call(exec, jsObject, callType, callData, jsThisObject, argList)); + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); result = 0; + } return result; } @@ -574,7 +561,7 @@ bool JSObjectIsConstructor(JSContextRef, JSObjectRef object) JSObjectRef JSObjectCallAsConstructor(JSContextRef ctx, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); if (!object) return 0; @@ -589,10 +576,13 @@ JSObjectRef JSObjectCallAsConstructor(JSContextRef ctx, JSObjectRef object, size MarkedArgumentBuffer argList; for (size_t i = 0; i < argumentCount; i++) argList.append(toJS(exec, arguments[i])); - - JSObjectRef result = toRef(profiledConstruct(exec, ProfilingReason::API, jsObject, constructType, constructData, argList)); - if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow) + JSObjectRef result = toRef(construct(exec, jsObject, constructType, constructData, argList)); + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); result = 0; + } return result; } @@ -616,15 +606,15 @@ JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef ctx, JSObjectRef o ASSERT_NOT_REACHED(); return 0; } + JSObject* jsObject = toJS(object); ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); VM* vm = &exec->vm(); - JSObject* jsObject = toJS(object); JSPropertyNameArrayRef propertyNames = new OpaqueJSPropertyNameArray(vm); - PropertyNameArray array(vm, PropertyNameMode::Strings); - jsObject->methodTable()->getPropertyNames(jsObject, exec, array, EnumerationMode()); + PropertyNameArray array(vm); + jsObject->methodTable()->getPropertyNames(jsObject, exec, array, ExcludeDontEnumProperties); size_t size = array.size(); propertyNames->array.reserveInitialCapacity(size); @@ -643,7 +633,7 @@ JSPropertyNameArrayRef JSPropertyNameArrayRetain(JSPropertyNameArrayRef array) void JSPropertyNameArrayRelease(JSPropertyNameArrayRef array) { if (--array->refCount == 0) { - JSLockHolder locker(array->vm); + APIEntryShim entryShim(array->vm, false); delete array; } } @@ -661,6 +651,6 @@ JSStringRef JSPropertyNameArrayGetNameAtIndex(JSPropertyNameArrayRef array, size void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef array, JSStringRef propertyName) { PropertyNameArray* propertyNames = toJS(array); - JSLockHolder locker(propertyNames->vm()); + APIEntryShim entryShim(propertyNames->vm()); propertyNames->add(propertyName->identifier(propertyNames->vm())); } -- cgit v1.2.1