X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/9dae56ea45a0f5f8136a5c93d6f3a7f99399ca73..f9bf01c6616d5ddcf65b13b33cedf9e387ff7a63:/API/JSValueRef.cpp diff --git a/API/JSValueRef.cpp b/API/JSValueRef.cpp index 7080952..a12cc34 100644 --- a/API/JSValueRef.cpp +++ b/API/JSValueRef.cpp @@ -28,6 +28,7 @@ #include #include "APICast.h" +#include "APIShims.h" #include "JSCallbackObject.h" #include @@ -41,9 +42,15 @@ #include // for std::min -JSType JSValueGetType(JSContextRef, JSValueRef value) +using namespace JSC; + +::JSType JSValueGetType(JSContextRef ctx, JSValueRef value) { - JSC::JSValuePtr jsValue = toJS(value); + ExecState* exec = toJS(ctx); + APIEntryShim entryShim(exec); + + JSValue jsValue = toJS(exec, value); + if (jsValue.isUndefined()) return kJSTypeUndefined; if (jsValue.isNull()) @@ -58,47 +65,66 @@ JSType JSValueGetType(JSContextRef, JSValueRef value) return kJSTypeObject; } -using namespace JSC; // placed here to avoid conflict between JSC::JSType and JSType, above. - -bool JSValueIsUndefined(JSContextRef, JSValueRef value) +bool JSValueIsUndefined(JSContextRef ctx, JSValueRef value) { - JSValuePtr jsValue = toJS(value); + ExecState* exec = toJS(ctx); + APIEntryShim entryShim(exec); + + JSValue jsValue = toJS(exec, value); return jsValue.isUndefined(); } -bool JSValueIsNull(JSContextRef, JSValueRef value) +bool JSValueIsNull(JSContextRef ctx, JSValueRef value) { - JSValuePtr jsValue = toJS(value); + ExecState* exec = toJS(ctx); + APIEntryShim entryShim(exec); + + JSValue jsValue = toJS(exec, value); return jsValue.isNull(); } -bool JSValueIsBoolean(JSContextRef, JSValueRef value) +bool JSValueIsBoolean(JSContextRef ctx, JSValueRef value) { - JSValuePtr jsValue = toJS(value); + ExecState* exec = toJS(ctx); + APIEntryShim entryShim(exec); + + JSValue jsValue = toJS(exec, value); return jsValue.isBoolean(); } -bool JSValueIsNumber(JSContextRef, JSValueRef value) +bool JSValueIsNumber(JSContextRef ctx, JSValueRef value) { - JSValuePtr jsValue = toJS(value); + ExecState* exec = toJS(ctx); + APIEntryShim entryShim(exec); + + JSValue jsValue = toJS(exec, value); return jsValue.isNumber(); } -bool JSValueIsString(JSContextRef, JSValueRef value) +bool JSValueIsString(JSContextRef ctx, JSValueRef value) { - JSValuePtr jsValue = toJS(value); + ExecState* exec = toJS(ctx); + APIEntryShim entryShim(exec); + + JSValue jsValue = toJS(exec, value); return jsValue.isString(); } -bool JSValueIsObject(JSContextRef, JSValueRef value) +bool JSValueIsObject(JSContextRef ctx, JSValueRef value) { - JSValuePtr jsValue = toJS(value); + ExecState* exec = toJS(ctx); + APIEntryShim entryShim(exec); + + JSValue jsValue = toJS(exec, value); return jsValue.isObject(); } -bool JSValueIsObjectOfClass(JSContextRef, JSValueRef value, JSClassRef jsClass) +bool JSValueIsObjectOfClass(JSContextRef ctx, JSValueRef value, JSClassRef jsClass) { - JSValuePtr jsValue = toJS(value); + ExecState* exec = toJS(ctx); + APIEntryShim entryShim(exec); + + JSValue jsValue = toJS(exec, value); if (JSObject* o = jsValue.getObject()) { if (o->inherits(&JSCallbackObject::info)) @@ -112,101 +138,110 @@ bool JSValueIsObjectOfClass(JSContextRef, JSValueRef value, JSClassRef jsClass) bool JSValueIsEqual(JSContextRef ctx, JSValueRef a, JSValueRef b, JSValueRef* exception) { ExecState* exec = toJS(ctx); - exec->globalData().heap.registerThread(); - JSLock lock(exec); + APIEntryShim entryShim(exec); - JSValuePtr jsA = toJS(a); - JSValuePtr jsB = toJS(b); + JSValue jsA = toJS(exec, a); + JSValue jsB = toJS(exec, b); - bool result = JSValuePtr::equal(exec, jsA, jsB); // false if an exception is thrown + bool result = JSValue::equal(exec, jsA, jsB); // false if an exception is thrown if (exec->hadException()) { if (exception) - *exception = toRef(exec->exception()); + *exception = toRef(exec, exec->exception()); exec->clearException(); } return result; } -bool JSValueIsStrictEqual(JSContextRef, JSValueRef a, JSValueRef b) +bool JSValueIsStrictEqual(JSContextRef ctx, JSValueRef a, JSValueRef b) { - JSValuePtr jsA = toJS(a); - JSValuePtr jsB = toJS(b); - - bool result = JSValuePtr::strictEqual(jsA, jsB); - return result; + ExecState* exec = toJS(ctx); + APIEntryShim entryShim(exec); + + JSValue jsA = toJS(exec, a); + JSValue jsB = toJS(exec, b); + + return JSValue::strictEqual(exec, jsA, jsB); } bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObjectRef constructor, JSValueRef* exception) { ExecState* exec = toJS(ctx); - exec->globalData().heap.registerThread(); - JSLock lock(exec); + APIEntryShim entryShim(exec); + + JSValue jsValue = toJS(exec, value); - JSValuePtr jsValue = toJS(value); JSObject* jsConstructor = toJS(constructor); if (!jsConstructor->structure()->typeInfo().implementsHasInstance()) return false; bool result = jsConstructor->hasInstance(exec, jsValue, jsConstructor->get(exec, exec->propertyNames().prototype)); // false if an exception is thrown if (exec->hadException()) { if (exception) - *exception = toRef(exec->exception()); + *exception = toRef(exec, exec->exception()); exec->clearException(); } return result; } -JSValueRef JSValueMakeUndefined(JSContextRef) +JSValueRef JSValueMakeUndefined(JSContextRef ctx) { - return toRef(jsUndefined()); + ExecState* exec = toJS(ctx); + APIEntryShim entryShim(exec); + + return toRef(exec, jsUndefined()); } -JSValueRef JSValueMakeNull(JSContextRef) +JSValueRef JSValueMakeNull(JSContextRef ctx) { - return toRef(jsNull()); + ExecState* exec = toJS(ctx); + APIEntryShim entryShim(exec); + + return toRef(exec, jsNull()); } -JSValueRef JSValueMakeBoolean(JSContextRef, bool value) +JSValueRef JSValueMakeBoolean(JSContextRef ctx, bool value) { - return toRef(jsBoolean(value)); + ExecState* exec = toJS(ctx); + APIEntryShim entryShim(exec); + + return toRef(exec, jsBoolean(value)); } JSValueRef JSValueMakeNumber(JSContextRef ctx, double value) { ExecState* exec = toJS(ctx); - exec->globalData().heap.registerThread(); - JSLock lock(exec); + APIEntryShim entryShim(exec); - return toRef(jsNumber(exec, value)); + return toRef(exec, jsNumber(exec, value)); } JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string) { ExecState* exec = toJS(ctx); - exec->globalData().heap.registerThread(); - JSLock lock(exec); + APIEntryShim entryShim(exec); - return toRef(jsString(exec, string->ustring())); + return toRef(exec, jsString(exec, string->ustring())); } bool JSValueToBoolean(JSContextRef ctx, JSValueRef value) { ExecState* exec = toJS(ctx); - JSValuePtr jsValue = toJS(value); + APIEntryShim entryShim(exec); + + JSValue jsValue = toJS(exec, value); return jsValue.toBoolean(exec); } double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception) { ExecState* exec = toJS(ctx); - exec->globalData().heap.registerThread(); - JSLock lock(exec); + APIEntryShim entryShim(exec); - JSValuePtr jsValue = toJS(value); + JSValue jsValue = toJS(exec, value); double number = jsValue.toNumber(exec); if (exec->hadException()) { if (exception) - *exception = toRef(exec->exception()); + *exception = toRef(exec, exec->exception()); exec->clearException(); number = NaN; } @@ -216,15 +251,14 @@ double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JSValueRef* exception) { ExecState* exec = toJS(ctx); - exec->globalData().heap.registerThread(); - JSLock lock(exec); + APIEntryShim entryShim(exec); - JSValuePtr jsValue = toJS(value); + JSValue jsValue = toJS(exec, value); RefPtr stringRef(OpaqueJSString::create(jsValue.toString(exec))); if (exec->hadException()) { if (exception) - *exception = toRef(exec->exception()); + *exception = toRef(exec, exec->exception()); exec->clearException(); stringRef.clear(); } @@ -234,15 +268,14 @@ JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JSValueRef* JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exception) { ExecState* exec = toJS(ctx); - exec->globalData().heap.registerThread(); - JSLock lock(exec); + APIEntryShim entryShim(exec); - JSValuePtr jsValue = toJS(value); + JSValue jsValue = toJS(exec, value); JSObjectRef objectRef = toRef(jsValue.toObject(exec)); if (exec->hadException()) { if (exception) - *exception = toRef(exec->exception()); + *exception = toRef(exec, exec->exception()); exec->clearException(); objectRef = 0; } @@ -252,19 +285,17 @@ JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exce void JSValueProtect(JSContextRef ctx, JSValueRef value) { ExecState* exec = toJS(ctx); - exec->globalData().heap.registerThread(); - JSLock lock(exec); + APIEntryShim entryShim(exec); - JSValuePtr jsValue = toJS(value); + JSValue jsValue = toJSForGC(exec, value); gcProtect(jsValue); } void JSValueUnprotect(JSContextRef ctx, JSValueRef value) { ExecState* exec = toJS(ctx); - exec->globalData().heap.registerThread(); - JSLock lock(exec); + APIEntryShim entryShim(exec); - JSValuePtr jsValue = toJS(value); + JSValue jsValue = toJSForGC(exec, value); gcUnprotect(jsValue); }