Skip to content

Commit 874ce9f

Browse files
6531.21.9
1 parent a0eb0e8 commit 874ce9f

94 files changed

Lines changed: 12303 additions & 2752 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

API/APICast.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#ifndef APICast_h
2727
#define APICast_h
2828

29-
#include "JSNumberCell.h"
29+
#include "JSAPIValueWrapper.h"
3030
#include "JSValue.h"
3131
#include <wtf/Platform.h>
3232
#include <wtf/UnusedParam.h>
@@ -58,18 +58,18 @@ inline JSC::ExecState* toJS(JSGlobalContextRef c)
5858
return reinterpret_cast<JSC::ExecState*>(c);
5959
}
6060

61-
inline JSC::JSValue toJS(JSC::ExecState* exec, JSValueRef v)
61+
inline JSC::JSValue toJS(JSC::ExecState*, JSValueRef v)
6262
{
63-
JSC::JSValue jsValue = JSC::JSValue::decode(reinterpret_cast<JSC::EncodedJSValue>(const_cast<OpaqueJSValue*>(v)));
64-
#if USE(ALTERNATE_JSIMMEDIATE)
65-
UNUSED_PARAM(exec);
63+
#if USE(JSVALUE32_64)
64+
JSC::JSCell* jsCell = reinterpret_cast<JSC::JSCell*>(const_cast<OpaqueJSValue*>(v));
65+
if (!jsCell)
66+
return JSC::JSValue();
67+
if (jsCell->isAPIValueWrapper())
68+
return static_cast<JSC::JSAPIValueWrapper*>(jsCell)->value();
69+
return jsCell;
6670
#else
67-
if (jsValue && jsValue.isNumber()) {
68-
ASSERT(jsValue.isAPIMangledNumber());
69-
return JSC::jsNumber(exec, jsValue.uncheckedGetNumber());
70-
}
71+
return JSC::JSValue::decode(reinterpret_cast<JSC::EncodedJSValue>(const_cast<OpaqueJSValue*>(v)));
7172
#endif
72-
return jsValue;
7373
}
7474

7575
inline JSC::JSObject* toJS(JSObjectRef o)
@@ -89,15 +89,16 @@ inline JSC::JSGlobalData* toJS(JSContextGroupRef g)
8989

9090
inline JSValueRef toRef(JSC::ExecState* exec, JSC::JSValue v)
9191
{
92-
#if USE(ALTERNATE_JSIMMEDIATE)
93-
UNUSED_PARAM(exec);
92+
#if USE(JSVALUE32_64)
93+
if (!v)
94+
return 0;
95+
if (!v.isCell())
96+
return reinterpret_cast<JSValueRef>(asCell(JSC::jsAPIValueWrapper(exec, v)));
97+
return reinterpret_cast<JSValueRef>(asCell(v));
9498
#else
95-
if (v && v.isNumber()) {
96-
ASSERT(!v.isAPIMangledNumber());
97-
return reinterpret_cast<JSValueRef>(JSC::JSValue::encode(JSC::jsAPIMangledNumber(exec, v.uncheckedGetNumber())));
98-
}
99-
#endif
99+
UNUSED_PARAM(exec);
100100
return reinterpret_cast<JSValueRef>(JSC::JSValue::encode(v));
101+
#endif
101102
}
102103

103104
inline JSObjectRef toRef(JSC::JSObject* o)

API/JSCallbackObjectFunctions.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,12 @@ bool JSCallbackObject<Base>::hasInstance(ExecState* exec, JSValue value, JSValue
318318

319319
for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
320320
if (JSObjectHasInstanceCallback hasInstance = jsClass->hasInstance) {
321+
JSValueRef valueRef = toRef(exec, value);
321322
JSValueRef exception = 0;
322323
bool result;
323324
{
324325
JSLock::DropAllLocks dropAllLocks(exec);
325-
result = hasInstance(execRef, thisRef, toRef(exec, value), &exception);
326+
result = hasInstance(execRef, thisRef, valueRef, &exception);
326327
}
327328
exec->setException(toJS(exec, exception));
328329
return result;
@@ -428,11 +429,13 @@ double JSCallbackObject<Base>::toNumber(ExecState* exec) const
428429
JSLock::DropAllLocks dropAllLocks(exec);
429430
value = convertToType(ctx, thisRef, kJSTypeNumber, &exception);
430431
}
431-
exec->setException(toJS(exec, exception));
432-
if (value) {
433-
double dValue;
434-
return toJS(exec, value).getNumber(dValue) ? dValue : NaN;
432+
if (exception) {
433+
exec->setException(toJS(exec, exception));
434+
return 0;
435435
}
436+
437+
double dValue;
438+
return toJS(exec, value).getNumber(dValue) ? dValue : NaN;
436439
}
437440

438441
return Base::toNumber(exec);
@@ -452,11 +455,11 @@ UString JSCallbackObject<Base>::toString(ExecState* exec) const
452455
JSLock::DropAllLocks dropAllLocks(exec);
453456
value = convertToType(ctx, thisRef, kJSTypeString, &exception);
454457
}
455-
exec->setException(toJS(exec, exception));
456-
if (value)
457-
return toJS(exec, value).getString();
458-
if (exception)
458+
if (exception) {
459+
exec->setException(toJS(exec, exception));
459460
return "";
461+
}
462+
return toJS(exec, value).getString();
460463
}
461464

462465
return Base::toString(exec);

API/tests/testapi.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,12 @@ static JSValueRef EvilExceptionObject_convertToType(JSContextRef context, JSObje
383383
if (!function)
384384
return NULL;
385385
JSValueRef value = JSObjectCallAsFunction(context, function, object, 0, NULL, exception);
386-
if (!value)
387-
return (JSValueRef)JSStringCreateWithUTF8CString("convertToType failed");
386+
if (!value) {
387+
JSStringRef errorString = JSStringCreateWithUTF8CString("convertToType failed");
388+
JSValueRef errorStringRef = JSValueMakeString(context, errorString);
389+
JSStringRelease(errorString);
390+
return errorStringRef;
391+
}
388392
return value;
389393
}
390394

AllInOneFile.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "runtime/JSStaticScopeObject.cpp"
3535
#include "runtime/JSFunction.cpp"
3636
#include "runtime/Arguments.cpp"
37+
#include "runtime/JSAPIValueWrapper.cpp"
3738
#include "runtime/JSGlobalObjectFunctions.cpp"
3839
#include "runtime/PrototypeFunction.cpp"
3940
#include "runtime/GlobalEvalFunction.cpp"

0 commit comments

Comments
 (0)