Skip to content

Commit 45a14ab

Browse files
committed
Update Sources To JavaScriptCore-7611.3.10.1.3
1 parent 72c9cf7 commit 45a14ab

File tree

2,646 files changed

+236931
-409865
lines changed

Some content is hidden

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

2,646 files changed

+236931
-409865
lines changed

.gitignore

-1
This file was deleted.

API/APICallbackFunction.h

+50-31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2013, 2016 Apple Inc. All rights reserved.
2+
* Copyright (C) 2013-2020 Apple Inc. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -35,77 +35,96 @@
3535
namespace JSC {
3636

3737
struct APICallbackFunction {
38-
39-
template <typename T> static EncodedJSValue JSC_HOST_CALL call(ExecState*);
40-
template <typename T> static EncodedJSValue JSC_HOST_CALL construct(ExecState*);
41-
38+
template <typename T> static EncodedJSValue callImpl(JSGlobalObject*, CallFrame*);
39+
template <typename T> static EncodedJSValue constructImpl(JSGlobalObject*, CallFrame*);
4240
};
4341

4442
template <typename T>
45-
EncodedJSValue JSC_HOST_CALL APICallbackFunction::call(ExecState* exec)
43+
EncodedJSValue APICallbackFunction::callImpl(JSGlobalObject* globalObject, CallFrame* callFrame)
4644
{
47-
VM& vm = exec->vm();
45+
VM& vm = getVM(globalObject);
4846
auto scope = DECLARE_THROW_SCOPE(vm);
49-
JSContextRef execRef = toRef(exec);
50-
JSObjectRef functionRef = toRef(exec->jsCallee());
51-
JSObjectRef thisObjRef = toRef(jsCast<JSObject*>(exec->thisValue().toThis(exec, NotStrictMode)));
47+
JSContextRef execRef = toRef(globalObject);
48+
JSObjectRef functionRef = toRef(callFrame->jsCallee());
49+
JSObjectRef thisObjRef = toRef(jsCast<JSObject*>(callFrame->thisValue().toThis(globalObject, ECMAMode::sloppy())));
5250

53-
int argumentCount = static_cast<int>(exec->argumentCount());
51+
int argumentCount = static_cast<int>(callFrame->argumentCount());
5452
Vector<JSValueRef, 16> arguments;
5553
arguments.reserveInitialCapacity(argumentCount);
5654
for (int i = 0; i < argumentCount; i++)
57-
arguments.uncheckedAppend(toRef(exec, exec->uncheckedArgument(i)));
55+
arguments.uncheckedAppend(toRef(globalObject, callFrame->uncheckedArgument(i)));
5856

59-
JSValueRef exception = 0;
57+
JSValueRef exception = nullptr;
6058
JSValueRef result;
6159
{
62-
JSLock::DropAllLocks dropAllLocks(exec);
60+
JSLock::DropAllLocks dropAllLocks(globalObject);
6361
result = jsCast<T*>(toJS(functionRef))->functionCallback()(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), &exception);
6462
}
65-
if (exception)
66-
throwException(exec, scope, toJS(exec, exception));
63+
if (exception) {
64+
throwException(globalObject, scope, toJS(globalObject, exception));
65+
return JSValue::encode(jsUndefined());
66+
}
6767

6868
// result must be a valid JSValue.
6969
if (!result)
7070
return JSValue::encode(jsUndefined());
7171

72-
return JSValue::encode(toJS(exec, result));
72+
return JSValue::encode(toJS(globalObject, result));
7373
}
7474

7575
template <typename T>
76-
EncodedJSValue JSC_HOST_CALL APICallbackFunction::construct(ExecState* exec)
76+
EncodedJSValue APICallbackFunction::constructImpl(JSGlobalObject* globalObject, CallFrame* callFrame)
7777
{
78-
VM& vm = exec->vm();
78+
VM& vm = getVM(globalObject);
7979
auto scope = DECLARE_THROW_SCOPE(vm);
80-
JSObject* constructor = exec->jsCallee();
81-
JSContextRef ctx = toRef(exec);
80+
JSValue callee = callFrame->jsCallee();
81+
T* constructor = jsCast<T*>(callFrame->jsCallee());
82+
JSContextRef ctx = toRef(globalObject);
8283
JSObjectRef constructorRef = toRef(constructor);
8384

84-
JSObjectCallAsConstructorCallback callback = jsCast<T*>(constructor)->constructCallback();
85+
JSObjectCallAsConstructorCallback callback = constructor->constructCallback();
8586
if (callback) {
86-
size_t argumentCount = exec->argumentCount();
87+
JSValue prototype;
88+
JSValue newTarget = callFrame->newTarget();
89+
// If we are doing a derived class construction get the .prototype property off the new target first so we behave closer to normal JS.
90+
if (newTarget != constructor) {
91+
prototype = newTarget.get(globalObject, vm.propertyNames->prototype);
92+
RETURN_IF_EXCEPTION(scope, { });
93+
}
94+
95+
size_t argumentCount = callFrame->argumentCount();
8796
Vector<JSValueRef, 16> arguments;
8897
arguments.reserveInitialCapacity(argumentCount);
8998
for (size_t i = 0; i < argumentCount; ++i)
90-
arguments.uncheckedAppend(toRef(exec, exec->uncheckedArgument(i)));
99+
arguments.uncheckedAppend(toRef(globalObject, callFrame->uncheckedArgument(i)));
91100

92-
JSValueRef exception = 0;
101+
JSValueRef exception = nullptr;
93102
JSObjectRef result;
94103
{
95-
JSLock::DropAllLocks dropAllLocks(exec);
104+
JSLock::DropAllLocks dropAllLocks(globalObject);
96105
result = callback(ctx, constructorRef, argumentCount, arguments.data(), &exception);
97106
}
107+
98108
if (exception) {
99-
throwException(exec, scope, toJS(exec, exception));
100-
return JSValue::encode(toJS(exec, exception));
109+
throwException(globalObject, scope, toJS(globalObject, exception));
110+
return JSValue::encode(jsUndefined());
101111
}
102112
// result must be a valid JSValue.
103113
if (!result)
104-
return throwVMTypeError(exec, scope);
105-
return JSValue::encode(toJS(result));
114+
return throwVMTypeError(globalObject, scope);
115+
116+
JSObject* newObject = toJS(result);
117+
// This won't trigger proxy traps on newObject's prototype handler but that's probably desirable here anyway.
118+
if (newTarget != constructor && newObject->getPrototypeDirect(vm) == constructor->get(globalObject, vm.propertyNames->prototype)) {
119+
RETURN_IF_EXCEPTION(scope, { });
120+
newObject->setPrototype(vm, globalObject, prototype);
121+
RETURN_IF_EXCEPTION(scope, { });
122+
}
123+
124+
return JSValue::encode(newObject);
106125
}
107126

108-
return JSValue::encode(toJS(JSObjectMake(ctx, jsCast<JSCallbackConstructor*>(constructor)->classRef(), 0)));
127+
return JSValue::encode(toJS(JSObjectMake(ctx, jsCast<JSCallbackConstructor*>(callee)->classRef(), nullptr)));
109128
}
110129

111130
} // namespace JSC

API/APICast.h

+36-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2006 Apple Inc. All rights reserved.
2+
* Copyright (C) 2006-2019 Apple Inc. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -33,7 +33,7 @@
3333
#include "HeapCellInlines.h"
3434

3535
namespace JSC {
36-
class ExecState;
36+
class CallFrame;
3737
class PropertyNameArray;
3838
class VM;
3939
class JSObject;
@@ -49,26 +49,26 @@ typedef struct OpaqueJSValue* JSObjectRef;
4949

5050
/* Opaque typing convenience methods */
5151

52-
inline JSC::ExecState* toJS(JSContextRef c)
52+
inline JSC::JSGlobalObject* toJS(JSContextRef context)
5353
{
54-
ASSERT(c);
55-
return reinterpret_cast<JSC::ExecState*>(const_cast<OpaqueJSContext*>(c));
54+
ASSERT(context);
55+
return reinterpret_cast<JSC::JSGlobalObject*>(const_cast<OpaqueJSContext*>(context));
5656
}
5757

58-
inline JSC::ExecState* toJS(JSGlobalContextRef c)
58+
inline JSC::JSGlobalObject* toJS(JSGlobalContextRef context)
5959
{
60-
ASSERT(c);
61-
return reinterpret_cast<JSC::ExecState*>(c);
60+
ASSERT(context);
61+
return reinterpret_cast<JSC::JSGlobalObject*>(context);
6262
}
6363

6464
inline JSC::JSGlobalObject* toJSGlobalObject(JSGlobalContextRef context)
6565
{
66-
return toJS(context)->lexicalGlobalObject();
66+
return toJS(context);
6767
}
6868

69-
inline JSC::JSValue toJS(JSC::ExecState* exec, JSValueRef v)
69+
inline JSC::JSValue toJS(JSC::JSGlobalObject* globalObject, JSValueRef v)
7070
{
71-
ASSERT_UNUSED(exec, exec);
71+
ASSERT_UNUSED(globalObject, globalObject);
7272
#if !CPU(ADDRESS64)
7373
JSC::JSCell* jsCell = reinterpret_cast<JSC::JSCell*>(const_cast<OpaqueJSValue*>(v));
7474
if (!jsCell)
@@ -84,13 +84,20 @@ inline JSC::JSValue toJS(JSC::ExecState* exec, JSValueRef v)
8484
if (!result)
8585
return JSC::jsNull();
8686
if (result.isCell())
87-
RELEASE_ASSERT(result.asCell()->methodTable(exec->vm()));
87+
RELEASE_ASSERT(result.asCell()->methodTable(getVM(globalObject)));
8888
return result;
8989
}
9090

91-
inline JSC::JSValue toJSForGC(JSC::ExecState* exec, JSValueRef v)
91+
#if CPU(ADDRESS64)
92+
inline JSC::JSValue toJS(JSValueRef value)
9293
{
93-
ASSERT_UNUSED(exec, exec);
94+
return bitwise_cast<JSC::JSValue>(value);
95+
}
96+
#endif
97+
98+
inline JSC::JSValue toJSForGC(JSC::JSGlobalObject* globalObject, JSValueRef v)
99+
{
100+
ASSERT_UNUSED(globalObject, globalObject);
94101
#if !CPU(ADDRESS64)
95102
JSC::JSCell* jsCell = reinterpret_cast<JSC::JSCell*>(const_cast<OpaqueJSValue*>(v));
96103
if (!jsCell)
@@ -100,7 +107,7 @@ inline JSC::JSValue toJSForGC(JSC::ExecState* exec, JSValueRef v)
100107
JSC::JSValue result = bitwise_cast<JSC::JSValue>(v);
101108
#endif
102109
if (result && result.isCell())
103-
RELEASE_ASSERT(result.asCell()->methodTable(exec->vm()));
110+
RELEASE_ASSERT(result.asCell()->methodTable(getVM(globalObject)));
104111
return result;
105112
}
106113

@@ -114,7 +121,7 @@ inline JSC::JSObject* toJS(JSObjectRef o)
114121
{
115122
JSC::JSObject* object = uncheckedToJS(o);
116123
if (object)
117-
RELEASE_ASSERT(object->methodTable(*object->vm()));
124+
RELEASE_ASSERT(object->methodTable(object->vm()));
118125
return object;
119126
}
120127

@@ -143,11 +150,18 @@ inline JSValueRef toRef(JSC::VM& vm, JSC::JSValue v)
143150
#endif
144151
}
145152

146-
inline JSValueRef toRef(JSC::ExecState* exec, JSC::JSValue v)
153+
inline JSValueRef toRef(JSC::JSGlobalObject* globalObject, JSC::JSValue v)
147154
{
148-
return toRef(exec->vm(), v);
155+
return toRef(getVM(globalObject), v);
149156
}
150157

158+
#if CPU(ADDRESS64)
159+
inline JSValueRef toRef(JSC::JSValue v)
160+
{
161+
return bitwise_cast<JSValueRef>(v);
162+
}
163+
#endif
164+
151165
inline JSObjectRef toRef(JSC::JSObject* o)
152166
{
153167
return reinterpret_cast<JSObjectRef>(o);
@@ -158,15 +172,14 @@ inline JSObjectRef toRef(const JSC::JSObject* o)
158172
return reinterpret_cast<JSObjectRef>(const_cast<JSC::JSObject*>(o));
159173
}
160174

161-
inline JSContextRef toRef(JSC::ExecState* e)
175+
inline JSContextRef toRef(JSC::JSGlobalObject* globalObject)
162176
{
163-
return reinterpret_cast<JSContextRef>(e);
177+
return reinterpret_cast<JSContextRef>(globalObject);
164178
}
165179

166-
inline JSGlobalContextRef toGlobalRef(JSC::ExecState* e)
180+
inline JSGlobalContextRef toGlobalRef(JSC::JSGlobalObject* globalObject)
167181
{
168-
ASSERT(e == e->lexicalGlobalObject()->globalExec());
169-
return reinterpret_cast<JSGlobalContextRef>(e);
182+
return reinterpret_cast<JSGlobalContextRef>(globalObject);
170183
}
171184

172185
inline JSPropertyNameAccumulatorRef toRef(JSC::PropertyNameArray* l)

API/APIUtils.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,30 @@ enum class ExceptionStatus {
3737
DidNotThrow
3838
};
3939

40-
inline ExceptionStatus handleExceptionIfNeeded(JSC::CatchScope& scope, JSC::ExecState* exec, JSValueRef* returnedExceptionRef)
40+
inline ExceptionStatus handleExceptionIfNeeded(JSC::CatchScope& scope, JSContextRef ctx, JSValueRef* returnedExceptionRef)
4141
{
42+
JSC::JSGlobalObject* globalObject = toJS(ctx);
4243
if (UNLIKELY(scope.exception())) {
4344
JSC::Exception* exception = scope.exception();
4445
if (returnedExceptionRef)
45-
*returnedExceptionRef = toRef(exec, exception->value());
46+
*returnedExceptionRef = toRef(globalObject, exception->value());
4647
scope.clearException();
4748
#if ENABLE(REMOTE_INSPECTOR)
48-
scope.vm().vmEntryGlobalObject(exec)->inspectorController().reportAPIException(exec, exception);
49+
globalObject->inspectorController().reportAPIException(globalObject, exception);
4950
#endif
5051
return ExceptionStatus::DidThrow;
5152
}
5253
return ExceptionStatus::DidNotThrow;
5354
}
5455

55-
inline void setException(JSC::ExecState* exec, JSValueRef* returnedExceptionRef, JSC::JSValue exception)
56+
inline void setException(JSContextRef ctx, JSValueRef* returnedExceptionRef, JSC::JSValue exception)
5657
{
58+
JSC::JSGlobalObject* globalObject = toJS(ctx);
5759
if (returnedExceptionRef)
58-
*returnedExceptionRef = toRef(exec, exception);
60+
*returnedExceptionRef = toRef(globalObject, exception);
5961
#if ENABLE(REMOTE_INSPECTOR)
60-
JSC::VM& vm = exec->vm();
61-
vm.vmEntryGlobalObject(exec)->inspectorController().reportAPIException(exec, JSC::Exception::create(vm, exception));
62+
JSC::VM& vm = getVM(globalObject);
63+
globalObject->inspectorController().reportAPIException(globalObject, JSC::Exception::create(vm, exception));
6264
#endif
6365
}
6466

API/JSAPIGlobalObject.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,19 @@ const GlobalObjectMethodTable JSAPIGlobalObject::s_globalObjectMethodTable = {
4444
nullptr, // moduleLoaderCreateImportMetaProperties
4545
nullptr, // moduleLoaderEvaluate
4646
nullptr, // promiseRejectionTracker
47+
&reportUncaughtExceptionAtEventLoop,
48+
&currentScriptExecutionOwner,
49+
&scriptExecutionStatus,
4750
nullptr, // defaultLanguage
4851
nullptr, // compileStreaming
4952
nullptr, // instantiateStreaming
5053
};
5154

55+
void JSAPIGlobalObject::reportUncaughtExceptionAtEventLoop(JSGlobalObject* globalObject, Exception* exception)
56+
{
57+
Base::reportUncaughtExceptionAtEventLoop(globalObject, exception);
58+
}
59+
5260
}
5361

5462
#endif

API/JSAPIGlobalObject.h

+16-7
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,20 @@ OBJC_CLASS JSScript;
3131

3232
namespace JSC {
3333

34-
class JSAPIGlobalObject : public JSGlobalObject {
34+
class JSAPIGlobalObject final : public JSGlobalObject {
3535
public:
3636
using Base = JSGlobalObject;
3737

3838
DECLARE_EXPORT_INFO;
3939
static const GlobalObjectMethodTable s_globalObjectMethodTable;
4040

41+
static constexpr bool needsDestruction = true;
42+
template<typename CellType, SubspaceAccess mode>
43+
static IsoSubspace* subspaceFor(VM& vm)
44+
{
45+
return vm.apiGlobalObjectSpace<mode>();
46+
}
47+
4148
static JSAPIGlobalObject* create(VM& vm, Structure* structure)
4249
{
4350
auto* object = new (NotNull, allocateCell<JSAPIGlobalObject>(vm.heap)) JSAPIGlobalObject(vm, structure);
@@ -47,16 +54,18 @@ class JSAPIGlobalObject : public JSGlobalObject {
4754

4855
static Structure* createStructure(VM& vm, JSValue prototype)
4956
{
50-
auto* result = Structure::create(vm, 0, prototype, TypeInfo(GlobalObjectType, StructureFlags), info());
57+
auto* result = Structure::create(vm, nullptr, prototype, TypeInfo(GlobalObjectType, StructureFlags), info());
5158
result->setTransitionWatchpointIsLikelyToBeFired(true);
5259
return result;
5360
}
5461

55-
static JSInternalPromise* moduleLoaderImportModule(JSGlobalObject*, ExecState*, JSModuleLoader*, JSString* moduleNameValue, JSValue parameters, const SourceOrigin&);
56-
static Identifier moduleLoaderResolve(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue keyValue, JSValue referrerValue, JSValue);
57-
static JSInternalPromise* moduleLoaderFetch(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue);
58-
static JSObject* moduleLoaderCreateImportMetaProperties(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSModuleRecord*, JSValue);
59-
static JSValue moduleLoaderEvaluate(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue);
62+
static void reportUncaughtExceptionAtEventLoop(JSGlobalObject*, Exception*);
63+
64+
static JSInternalPromise* moduleLoaderImportModule(JSGlobalObject*, JSModuleLoader*, JSString* moduleNameValue, JSValue parameters, const SourceOrigin&);
65+
static Identifier moduleLoaderResolve(JSGlobalObject*, JSModuleLoader*, JSValue keyValue, JSValue referrerValue, JSValue);
66+
static JSInternalPromise* moduleLoaderFetch(JSGlobalObject*, JSModuleLoader*, JSValue, JSValue, JSValue);
67+
static JSObject* moduleLoaderCreateImportMetaProperties(JSGlobalObject*, JSModuleLoader*, JSValue, JSModuleRecord*, JSValue);
68+
static JSValue moduleLoaderEvaluate(JSGlobalObject*, JSModuleLoader*, JSValue, JSValue, JSValue);
6069

6170
JSValue loadAndEvaluateJSScriptModule(const JSLockHolder&, JSScript *);
6271

0 commit comments

Comments
 (0)