diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-04-10 09:28:39 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-04-10 09:28:39 +0000 |
commit | 32761a6cee1d0dee366b885b7b9c777e67885688 (patch) | |
tree | d6bec92bebfb216f4126356e55518842c2f476a1 /Source/JavaScriptCore/API/JSValueRef.cpp | |
parent | a4e969f4965059196ca948db781e52f7cfebf19e (diff) | |
download | WebKitGtk-tarball-32761a6cee1d0dee366b885b7b9c777e67885688.tar.gz |
webkitgtk-2.4.11webkitgtk-2.4.11
Diffstat (limited to 'Source/JavaScriptCore/API/JSValueRef.cpp')
-rw-r--r-- | Source/JavaScriptCore/API/JSValueRef.cpp | 191 |
1 files changed, 88 insertions, 103 deletions
diff --git a/Source/JavaScriptCore/API/JSValueRef.cpp b/Source/JavaScriptCore/API/JSValueRef.cpp index 54405e2af..3e0cbbd7a 100644 --- a/Source/JavaScriptCore/API/JSValueRef.cpp +++ b/Source/JavaScriptCore/API/JSValueRef.cpp @@ -10,69 +10,46 @@ * 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 * 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. + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" #include "JSValueRef.h" #include "APICast.h" -#include "DateInstance.h" -#include "Exception.h" +#include "APIShims.h" #include "JSAPIWrapperObject.h" -#include "JSCInlines.h" #include "JSCJSValue.h" #include "JSCallbackObject.h" #include "JSGlobalObject.h" #include "JSONObject.h" #include "JSString.h" #include "LiteralParser.h" +#include "Operations.h" #include "Protect.h" -#include <algorithm> + #include <wtf/Assertions.h> #include <wtf/text/StringHash.h> #include <wtf/text/WTFString.h> +#include <algorithm> // for std::min + #if PLATFORM(MAC) #include <mach-o/dyld.h> #endif -#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; -} - #if PLATFORM(MAC) static bool evernoteHackNeeded() { @@ -91,7 +68,7 @@ static bool evernoteHackNeeded() return kJSTypeUndefined; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSValue jsValue = toJS(exec, value); @@ -116,9 +93,10 @@ bool JSValueIsUndefined(JSContextRef ctx, JSValueRef value) return false; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); - return toJS(exec, value).isUndefined(); + JSValue jsValue = toJS(exec, value); + return jsValue.isUndefined(); } bool JSValueIsNull(JSContextRef ctx, JSValueRef value) @@ -128,9 +106,10 @@ bool JSValueIsNull(JSContextRef ctx, JSValueRef value) return false; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); - return toJS(exec, value).isNull(); + JSValue jsValue = toJS(exec, value); + return jsValue.isNull(); } bool JSValueIsBoolean(JSContextRef ctx, JSValueRef value) @@ -140,9 +119,10 @@ bool JSValueIsBoolean(JSContextRef ctx, JSValueRef value) return false; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); - return toJS(exec, value).isBoolean(); + JSValue jsValue = toJS(exec, value); + return jsValue.isBoolean(); } bool JSValueIsNumber(JSContextRef ctx, JSValueRef value) @@ -152,9 +132,10 @@ bool JSValueIsNumber(JSContextRef ctx, JSValueRef value) return false; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); - return toJS(exec, value).isNumber(); + JSValue jsValue = toJS(exec, value); + return jsValue.isNumber(); } bool JSValueIsString(JSContextRef ctx, JSValueRef value) @@ -164,9 +145,10 @@ bool JSValueIsString(JSContextRef ctx, JSValueRef value) return false; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); - return toJS(exec, value).isString(); + JSValue jsValue = toJS(exec, value); + return jsValue.isString(); } bool JSValueIsObject(JSContextRef ctx, JSValueRef value) @@ -176,33 +158,10 @@ bool JSValueIsObject(JSContextRef ctx, JSValueRef value) return false; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); - - return toJS(exec, value).isObject(); -} - -bool JSValueIsArray(JSContextRef ctx, JSValueRef value) -{ - if (!ctx) { - ASSERT_NOT_REACHED(); - return false; - } - ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); - - return toJS(exec, value).inherits(JSArray::info()); -} - -bool JSValueIsDate(JSContextRef ctx, JSValueRef value) -{ - if (!ctx) { - ASSERT_NOT_REACHED(); - return false; - } - ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); - return toJS(exec, value).inherits(DateInstance::info()); + JSValue jsValue = toJS(exec, value); + return jsValue.isObject(); } bool JSValueIsObjectOfClass(JSContextRef ctx, JSValueRef value, JSClassRef jsClass) @@ -212,14 +171,11 @@ bool JSValueIsObjectOfClass(JSContextRef ctx, JSValueRef value, JSClassRef jsCla return false; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSValue jsValue = toJS(exec, value); if (JSObject* o = jsValue.getObject()) { - if (o->inherits(JSProxy::info())) - o = jsCast<JSProxy*>(o)->target(); - if (o->inherits(JSCallbackObject<JSGlobalObject>::info())) return jsCast<JSCallbackObject<JSGlobalObject>*>(o)->inherits(jsClass); if (o->inherits(JSCallbackObject<JSDestructibleObject>::info())) @@ -239,14 +195,17 @@ bool JSValueIsEqual(JSContextRef ctx, JSValueRef a, JSValueRef b, JSValueRef* ex return false; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSValue jsA = toJS(exec, a); JSValue jsB = toJS(exec, b); bool result = JSValue::equal(exec, jsA, jsB); // false if an exception is thrown - handleExceptionIfNeeded(exec, exception); - + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); + } return result; } @@ -257,7 +216,7 @@ bool JSValueIsStrictEqual(JSContextRef ctx, JSValueRef a, JSValueRef b) return false; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSValue jsA = toJS(exec, a); JSValue jsB = toJS(exec, b); @@ -272,7 +231,7 @@ bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObject return false; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSValue jsValue = toJS(exec, value); @@ -280,7 +239,11 @@ bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObject if (!jsConstructor->structure()->typeInfo().implementsHasInstance()) return false; bool result = jsConstructor->hasInstance(exec, jsValue); // false if an exception is thrown - handleExceptionIfNeeded(exec, exception); + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); + } return result; } @@ -291,7 +254,7 @@ JSValueRef JSValueMakeUndefined(JSContextRef ctx) return 0; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); return toRef(exec, jsUndefined()); } @@ -303,7 +266,7 @@ JSValueRef JSValueMakeNull(JSContextRef ctx) return 0; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); return toRef(exec, jsNull()); } @@ -315,7 +278,7 @@ JSValueRef JSValueMakeBoolean(JSContextRef ctx, bool value) return 0; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); return toRef(exec, jsBoolean(value)); } @@ -327,9 +290,15 @@ JSValueRef JSValueMakeNumber(JSContextRef ctx, double value) return 0; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); - return toRef(exec, jsNumber(purifyNaN(value))); + // Our JSValue representation relies on a standard bit pattern for NaN. NaNs + // generated internally to JavaScriptCore naturally have that representation, + // but an external NaN might not. + if (std::isnan(value)) + value = QNaN; + + return toRef(exec, jsNumber(value)); } JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string) @@ -339,9 +308,9 @@ JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string) return 0; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); - return toRef(exec, jsString(exec, string ? string->string() : String())); + return toRef(exec, jsString(exec, string->string())); } JSValueRef JSValueMakeFromJSONString(JSContextRef ctx, JSStringRef string) @@ -351,14 +320,14 @@ JSValueRef JSValueMakeFromJSONString(JSContextRef ctx, JSStringRef string) return 0; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); String str = string->string(); unsigned length = str.length(); - if (!length || str.is8Bit()) { + if (length && str.is8Bit()) { LiteralParser<LChar> parser(exec, str.characters8(), length, StrictJSON); return toRef(exec, parser.tryLiteralParse()); } - LiteralParser<UChar> parser(exec, str.characters16(), length, StrictJSON); + LiteralParser<UChar> parser(exec, str.deprecatedCharacters(), length, StrictJSON); return toRef(exec, parser.tryLiteralParse()); } @@ -369,13 +338,17 @@ JSStringRef JSValueCreateJSONString(JSContextRef ctx, JSValueRef apiValue, unsig return 0; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSValue value = toJS(exec, apiValue); String result = JSONStringify(exec, value, indent); if (exception) *exception = 0; - if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow) + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); return 0; + } return OpaqueJSString::create(result).leakRef(); } @@ -386,7 +359,7 @@ bool JSValueToBoolean(JSContextRef ctx, JSValueRef value) return false; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSValue jsValue = toJS(exec, value); return jsValue.toBoolean(exec); @@ -396,16 +369,20 @@ double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception { if (!ctx) { ASSERT_NOT_REACHED(); - return PNaN; + return QNaN; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSValue jsValue = toJS(exec, value); double number = jsValue.toNumber(exec); - if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow) - number = PNaN; + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); + number = QNaN; + } return number; } @@ -416,13 +393,17 @@ JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JSValueRef* return 0; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSValue jsValue = toJS(exec, value); RefPtr<OpaqueJSString> stringRef(OpaqueJSString::create(jsValue.toString(exec)->value(exec))); - if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow) - stringRef = nullptr; + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); + stringRef.clear(); + } return stringRef.release().leakRef(); } @@ -433,15 +414,19 @@ JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exce return 0; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSValue jsValue = toJS(exec, value); JSObjectRef objectRef = toRef(jsValue.toObject(exec)); - if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow) + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); objectRef = 0; + } return objectRef; -} +} void JSValueProtect(JSContextRef ctx, JSValueRef value) { @@ -450,7 +435,7 @@ void JSValueProtect(JSContextRef ctx, JSValueRef value) return; } ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSValue jsValue = toJSForGC(exec, value); gcProtect(jsValue); @@ -464,7 +449,7 @@ void JSValueUnprotect(JSContextRef ctx, JSValueRef value) #endif ExecState* exec = toJS(ctx); - JSLockHolder locker(exec); + APIEntryShim entryShim(exec); JSValue jsValue = toJSForGC(exec, value); gcUnprotect(jsValue); |