summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/API/JSValueRef.cpp
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/API/JSValueRef.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/JavaScriptCore/API/JSValueRef.cpp')
-rw-r--r--Source/JavaScriptCore/API/JSValueRef.cpp187
1 files changed, 93 insertions, 94 deletions
diff --git a/Source/JavaScriptCore/API/JSValueRef.cpp b/Source/JavaScriptCore/API/JSValueRef.cpp
index 3e0cbbd7a..64ac6c324 100644
--- a/Source/JavaScriptCore/API/JSValueRef.cpp
+++ b/Source/JavaScriptCore/API/JSValueRef.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2007, 2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -10,44 +10,48 @@
* 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 COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE 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 COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE 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 "APIShims.h"
+#include "APIUtils.h"
+#include "DateInstance.h"
+#include "Exception.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;
#if PLATFORM(MAC)
@@ -68,7 +72,7 @@ static bool evernoteHackNeeded()
return kJSTypeUndefined;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
JSValue jsValue = toJS(exec, value);
@@ -93,10 +97,9 @@ bool JSValueIsUndefined(JSContextRef ctx, JSValueRef value)
return false;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
- JSValue jsValue = toJS(exec, value);
- return jsValue.isUndefined();
+ return toJS(exec, value).isUndefined();
}
bool JSValueIsNull(JSContextRef ctx, JSValueRef value)
@@ -106,10 +109,9 @@ bool JSValueIsNull(JSContextRef ctx, JSValueRef value)
return false;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
- JSValue jsValue = toJS(exec, value);
- return jsValue.isNull();
+ return toJS(exec, value).isNull();
}
bool JSValueIsBoolean(JSContextRef ctx, JSValueRef value)
@@ -119,10 +121,9 @@ bool JSValueIsBoolean(JSContextRef ctx, JSValueRef value)
return false;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
- JSValue jsValue = toJS(exec, value);
- return jsValue.isBoolean();
+ return toJS(exec, value).isBoolean();
}
bool JSValueIsNumber(JSContextRef ctx, JSValueRef value)
@@ -132,10 +133,9 @@ bool JSValueIsNumber(JSContextRef ctx, JSValueRef value)
return false;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
- JSValue jsValue = toJS(exec, value);
- return jsValue.isNumber();
+ return toJS(exec, value).isNumber();
}
bool JSValueIsString(JSContextRef ctx, JSValueRef value)
@@ -145,10 +145,9 @@ bool JSValueIsString(JSContextRef ctx, JSValueRef value)
return false;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
- JSValue jsValue = toJS(exec, value);
- return jsValue.isString();
+ return toJS(exec, value).isString();
}
bool JSValueIsObject(JSContextRef ctx, JSValueRef value)
@@ -158,10 +157,35 @@ bool JSValueIsObject(JSContextRef ctx, JSValueRef value)
return false;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
- JSValue jsValue = toJS(exec, value);
- return jsValue.isObject();
+ return toJS(exec, value).isObject();
+}
+
+bool JSValueIsArray(JSContextRef ctx, JSValueRef value)
+{
+ if (!ctx) {
+ ASSERT_NOT_REACHED();
+ return false;
+ }
+ ExecState* exec = toJS(ctx);
+ VM& vm = exec->vm();
+ JSLockHolder locker(exec);
+
+ return toJS(exec, value).inherits(vm, JSArray::info());
+}
+
+bool JSValueIsDate(JSContextRef ctx, JSValueRef value)
+{
+ if (!ctx) {
+ ASSERT_NOT_REACHED();
+ return false;
+ }
+ ExecState* exec = toJS(ctx);
+ VM& vm = exec->vm();
+ JSLockHolder locker(exec);
+
+ return toJS(exec, value).inherits(vm, DateInstance::info());
}
bool JSValueIsObjectOfClass(JSContextRef ctx, JSValueRef value, JSClassRef jsClass)
@@ -171,17 +195,21 @@ bool JSValueIsObjectOfClass(JSContextRef ctx, JSValueRef value, JSClassRef jsCla
return false;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ VM& vm = exec->vm();
+ JSLockHolder locker(exec);
JSValue jsValue = toJS(exec, value);
if (JSObject* o = jsValue.getObject()) {
- if (o->inherits(JSCallbackObject<JSGlobalObject>::info()))
+ if (o->inherits(vm, JSProxy::info()))
+ o = jsCast<JSProxy*>(o)->target();
+
+ if (o->inherits(vm, JSCallbackObject<JSGlobalObject>::info()))
return jsCast<JSCallbackObject<JSGlobalObject>*>(o)->inherits(jsClass);
- if (o->inherits(JSCallbackObject<JSDestructibleObject>::info()))
+ if (o->inherits(vm, JSCallbackObject<JSDestructibleObject>::info()))
return jsCast<JSCallbackObject<JSDestructibleObject>*>(o)->inherits(jsClass);
#if JSC_OBJC_API_ENABLED
- if (o->inherits(JSCallbackObject<JSAPIWrapperObject>::info()))
+ if (o->inherits(vm, JSCallbackObject<JSAPIWrapperObject>::info()))
return jsCast<JSCallbackObject<JSAPIWrapperObject>*>(o)->inherits(jsClass);
#endif
}
@@ -195,17 +223,14 @@ bool JSValueIsEqual(JSContextRef ctx, JSValueRef a, JSValueRef b, JSValueRef* ex
return false;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
JSValue jsA = toJS(exec, a);
JSValue jsB = toJS(exec, b);
bool result = JSValue::equal(exec, jsA, jsB); // false if an exception is thrown
- if (exec->hadException()) {
- if (exception)
- *exception = toRef(exec, exec->exception());
- exec->clearException();
- }
+ handleExceptionIfNeeded(exec, exception);
+
return result;
}
@@ -216,7 +241,7 @@ bool JSValueIsStrictEqual(JSContextRef ctx, JSValueRef a, JSValueRef b)
return false;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
JSValue jsA = toJS(exec, a);
JSValue jsB = toJS(exec, b);
@@ -231,7 +256,7 @@ bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObject
return false;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
JSValue jsValue = toJS(exec, value);
@@ -239,11 +264,7 @@ 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
- if (exec->hadException()) {
- if (exception)
- *exception = toRef(exec, exec->exception());
- exec->clearException();
- }
+ handleExceptionIfNeeded(exec, exception);
return result;
}
@@ -254,7 +275,7 @@ JSValueRef JSValueMakeUndefined(JSContextRef ctx)
return 0;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
return toRef(exec, jsUndefined());
}
@@ -266,7 +287,7 @@ JSValueRef JSValueMakeNull(JSContextRef ctx)
return 0;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
return toRef(exec, jsNull());
}
@@ -278,7 +299,7 @@ JSValueRef JSValueMakeBoolean(JSContextRef ctx, bool value)
return 0;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
return toRef(exec, jsBoolean(value));
}
@@ -290,15 +311,9 @@ JSValueRef JSValueMakeNumber(JSContextRef ctx, double value)
return 0;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
- // 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));
+ return toRef(exec, jsNumber(purifyNaN(value)));
}
JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string)
@@ -308,9 +323,9 @@ JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string)
return 0;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
- return toRef(exec, jsString(exec, string->string()));
+ return toRef(exec, jsString(exec, string ? string->string() : String()));
}
JSValueRef JSValueMakeFromJSONString(JSContextRef ctx, JSStringRef string)
@@ -320,14 +335,14 @@ JSValueRef JSValueMakeFromJSONString(JSContextRef ctx, JSStringRef string)
return 0;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(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.deprecatedCharacters(), length, StrictJSON);
+ LiteralParser<UChar> parser(exec, str.characters16(), length, StrictJSON);
return toRef(exec, parser.tryLiteralParse());
}
@@ -338,17 +353,13 @@ JSStringRef JSValueCreateJSONString(JSContextRef ctx, JSValueRef apiValue, unsig
return 0;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
JSValue value = toJS(exec, apiValue);
String result = JSONStringify(exec, value, indent);
if (exception)
*exception = 0;
- if (exec->hadException()) {
- if (exception)
- *exception = toRef(exec, exec->exception());
- exec->clearException();
+ if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow)
return 0;
- }
return OpaqueJSString::create(result).leakRef();
}
@@ -359,7 +370,7 @@ bool JSValueToBoolean(JSContextRef ctx, JSValueRef value)
return false;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
JSValue jsValue = toJS(exec, value);
return jsValue.toBoolean(exec);
@@ -369,20 +380,16 @@ double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception
{
if (!ctx) {
ASSERT_NOT_REACHED();
- return QNaN;
+ return PNaN;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
JSValue jsValue = toJS(exec, value);
double number = jsValue.toNumber(exec);
- if (exec->hadException()) {
- if (exception)
- *exception = toRef(exec, exec->exception());
- exec->clearException();
- number = QNaN;
- }
+ if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow)
+ number = PNaN;
return number;
}
@@ -393,18 +400,14 @@ JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JSValueRef*
return 0;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
JSValue jsValue = toJS(exec, value);
- RefPtr<OpaqueJSString> stringRef(OpaqueJSString::create(jsValue.toString(exec)->value(exec)));
- if (exec->hadException()) {
- if (exception)
- *exception = toRef(exec, exec->exception());
- exec->clearException();
- stringRef.clear();
- }
- return stringRef.release().leakRef();
+ auto stringRef(OpaqueJSString::create(jsValue.toWTFString(exec)));
+ if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow)
+ stringRef = nullptr;
+ return stringRef.leakRef();
}
JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exception)
@@ -414,19 +417,15 @@ JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exce
return 0;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
JSValue jsValue = toJS(exec, value);
JSObjectRef objectRef = toRef(jsValue.toObject(exec));
- if (exec->hadException()) {
- if (exception)
- *exception = toRef(exec, exec->exception());
- exec->clearException();
+ if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow)
objectRef = 0;
- }
return objectRef;
-}
+}
void JSValueProtect(JSContextRef ctx, JSValueRef value)
{
@@ -435,7 +434,7 @@ void JSValueProtect(JSContextRef ctx, JSValueRef value)
return;
}
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
JSValue jsValue = toJSForGC(exec, value);
gcProtect(jsValue);
@@ -449,7 +448,7 @@ void JSValueUnprotect(JSContextRef ctx, JSValueRef value)
#endif
ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
JSValue jsValue = toJSForGC(exec, value);
gcUnprotect(jsValue);