Commit a55a2447 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

Revert "[torque] typed context slot access"

This reverts commit 408e7240.

Reason for revert: debug builds fail

is_component_build = true
is_debug = true
use_goma = true
v8_enable_backtrace = true
v8_enable_debugging_features = true
v8_enable_fast_mksnapshot = true
v8_enable_slow_dchecks = true
v8_enable_snapshot_code_comments = true
v8_enable_verify_csa = true
v8_optimized_debug = false
v8_use_multi_snapshots = false

# Fatal error in ../../src/compiler/backend/instruction-selector.cc, line 3088
# Expected Turbofan static assert to hold, but got non-true input:
  static_assert(nativeContext == LoadNativeContext(context)) at src/builtins/promise-resolve.tq:45:5


Original change's description:
> [torque] typed context slot access
> 
> This introduces a new type Slot<ContextType, SlotType> that is used
> for enum values used to access context slots.
> Together with new types for the various custom contexts used in
> Torque, this results in fairly type-safe access to context slots,
> including the NativeContext's slots.
> 
> Drive-by changes:
> - Introduce a new header file to specify headers needed for
>   generated CSA headers, to reduce the amount of includes specified
>   in implementation-visitor.cc
> - Port AllocateSyntheticFunctionContext to Torque.
> 
> Bug: v8:7793
> Change-Id: I509a128916ca408eeeb636a9bcc376b2cc868532
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2335064
> Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> Reviewed-by: Seth Brenith <seth.brenith@microsoft.com>
> Cr-Commit-Position: refs/heads/master@{#69249}

TBR=tebbi@chromium.org,seth.brenith@microsoft.com

Change-Id: I90c014022a808449aca4a9b9b3c3b8e036beb28e
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7793
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2340903Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69256}
parent fe850a80
...@@ -1767,7 +1767,6 @@ v8_source_set("v8_initializers") { ...@@ -1767,7 +1767,6 @@ v8_source_set("v8_initializers") {
"src/builtins/profile-data-reader.cc", "src/builtins/profile-data-reader.cc",
"src/builtins/profile-data-reader.h", "src/builtins/profile-data-reader.h",
"src/builtins/setup-builtins-internal.cc", "src/builtins/setup-builtins-internal.cc",
"src/builtins/torque-csa-header-includes.h",
"src/codegen/code-stub-assembler.cc", "src/codegen/code-stub-assembler.cc",
"src/codegen/code-stub-assembler.h", "src/codegen/code-stub-assembler.h",
"src/heap/setup-heap-internal.cc", "src/heap/setup-heap-internal.cc",
......
...@@ -414,18 +414,17 @@ const kMinJoinStackSize: ...@@ -414,18 +414,17 @@ const kMinJoinStackSize:
constexpr int31 generates 'JSArray::kMinJoinStackSize'; constexpr int31 generates 'JSArray::kMinJoinStackSize';
macro LoadJoinStack(implicit context: Context)(): FixedArray macro LoadJoinStack(implicit context: Context)(): FixedArray
labels IfUninitialized { labels IfUninitialized {
typeswitch (*NativeContextSlot(ContextSlot::ARRAY_JOIN_STACK_INDEX)) { const nativeContext: NativeContext = LoadNativeContext(context);
case (Undefined): { const stack: HeapObject = UnsafeCast<HeapObject>(
goto IfUninitialized; nativeContext.elements[NativeContextSlot::ARRAY_JOIN_STACK_INDEX]);
} if (stack == Undefined) goto IfUninitialized;
case (stack: FixedArray): { assert(Is<FixedArray>(stack));
return stack; return UnsafeCast<FixedArray>(stack);
}
}
} }
macro SetJoinStack(implicit context: Context)(stack: FixedArray): void { macro SetJoinStack(implicit context: Context)(stack: FixedArray): void {
*NativeContextSlot(ContextSlot::ARRAY_JOIN_STACK_INDEX) = stack; const nativeContext: NativeContext = LoadNativeContext(context);
nativeContext.elements[NativeContextSlot::ARRAY_JOIN_STACK_INDEX] = stack;
} }
// Adds a receiver to the stack. The FixedArray will automatically grow to // Adds a receiver to the stack. The FixedArray will automatically grow to
......
...@@ -451,6 +451,8 @@ const UNSAFE_SKIP_WRITE_BARRIER: ...@@ -451,6 +451,8 @@ const UNSAFE_SKIP_WRITE_BARRIER:
extern transitioning macro AllocateJSIteratorResult(implicit context: Context)( extern transitioning macro AllocateJSIteratorResult(implicit context: Context)(
JSAny, Boolean): JSObject; JSAny, Boolean): JSObject;
extern macro AllocateSyntheticFunctionContext(
NativeContext, constexpr int32): Context;
extern class Filler extends HeapObject generates 'TNode<HeapObject>'; extern class Filler extends HeapObject generates 'TNode<HeapObject>';
...@@ -1100,47 +1102,74 @@ macro AllowNonNumberElements(kind: ElementsKind): ElementsKind { ...@@ -1100,47 +1102,74 @@ macro AllowNonNumberElements(kind: ElementsKind): ElementsKind {
} }
macro GetObjectFunction(implicit context: Context)(): JSFunction { macro GetObjectFunction(implicit context: Context)(): JSFunction {
return *NativeContextSlot(ContextSlot::OBJECT_FUNCTION_INDEX); return UnsafeCast<JSFunction>(
LoadNativeContext(context)
.elements[NativeContextSlot::OBJECT_FUNCTION_INDEX]);
} }
macro GetArrayFunction(implicit context: Context)(): JSFunction { macro GetArrayFunction(implicit context: Context)(): JSFunction {
return *NativeContextSlot(ContextSlot::ARRAY_FUNCTION_INDEX); return UnsafeCast<JSFunction>(
LoadNativeContext(context)
.elements[NativeContextSlot::ARRAY_FUNCTION_INDEX]);
} }
macro GetArrayBufferFunction(implicit context: Context)(): Constructor { macro GetArrayBufferFunction(implicit context: Context)(): Constructor {
return *NativeContextSlot(ContextSlot::ARRAY_BUFFER_FUN_INDEX); return UnsafeCast<Constructor>(
LoadNativeContext(context)
.elements[NativeContextSlot::ARRAY_BUFFER_FUN_INDEX]);
} }
macro GetArrayBufferNoInitFunction(implicit context: Context)(): JSFunction { macro GetArrayBufferNoInitFunction(implicit context: Context)(): JSFunction {
return *NativeContextSlot(ContextSlot::ARRAY_BUFFER_NOINIT_FUN_INDEX); return UnsafeCast<JSFunction>(
LoadNativeContext(context)
.elements[NativeContextSlot::ARRAY_BUFFER_NOINIT_FUN_INDEX]);
} }
macro GetFastPackedElementsJSArrayMap(implicit context: Context)(): Map { macro GetFastPackedElementsJSArrayMap(implicit context: Context)(): Map {
return *NativeContextSlot(ContextSlot::JS_ARRAY_PACKED_ELEMENTS_MAP_INDEX); return UnsafeCast<Map>(
LoadNativeContext(context)
.elements[NativeContextSlot::JS_ARRAY_PACKED_ELEMENTS_MAP_INDEX]);
} }
macro GetFastPackedSmiElementsJSArrayMap(implicit context: Context)(): Map { macro GetFastPackedSmiElementsJSArrayMap(implicit context: Context)(): Map {
return *NativeContextSlot( return UnsafeCast<Map>(
ContextSlot::JS_ARRAY_PACKED_SMI_ELEMENTS_MAP_INDEX); LoadNativeContext(context)
.elements[NativeContextSlot::JS_ARRAY_PACKED_SMI_ELEMENTS_MAP_INDEX]);
} }
macro GetProxyRevocableResultMap(implicit context: Context)(): Map { macro GetProxyRevocableResultMap(implicit context: Context)(): Map {
return *NativeContextSlot(ContextSlot::PROXY_REVOCABLE_RESULT_MAP_INDEX); return UnsafeCast<Map>(
LoadNativeContext(context)
.elements[NativeContextSlot::PROXY_REVOCABLE_RESULT_MAP_INDEX]);
} }
macro GetIteratorResultMap(implicit context: Context)(): Map { macro GetIteratorResultMap(implicit context: Context)(): Map {
return *NativeContextSlot(ContextSlot::ITERATOR_RESULT_MAP_INDEX); return UnsafeCast<Map>(
LoadNativeContext(context)
.elements[NativeContextSlot::ITERATOR_RESULT_MAP_INDEX]);
} }
macro GetInitialStringIteratorMap(implicit context: Context)(): Map { macro GetInitialStringIteratorMap(implicit context: Context)(): Map {
return *NativeContextSlot(ContextSlot::INITIAL_STRING_ITERATOR_MAP_INDEX); return UnsafeCast<Map>(
LoadNativeContext(context)
.elements[NativeContextSlot::INITIAL_STRING_ITERATOR_MAP_INDEX]);
} }
macro GetReflectApply(implicit context: Context)(): Callable { macro GetReflectApply(implicit context: Context)(): Callable {
return *NativeContextSlot(ContextSlot::REFLECT_APPLY_INDEX); return UnsafeCast<Callable>(
LoadNativeContext(context)
.elements[NativeContextSlot::REFLECT_APPLY_INDEX]);
} }
macro GetRegExpLastMatchInfo(implicit context: Context)(): RegExpMatchInfo { macro GetRegExpLastMatchInfo(implicit context: Context)(): RegExpMatchInfo {
return *NativeContextSlot(ContextSlot::REGEXP_LAST_MATCH_INFO_INDEX); return %RawDownCast<RegExpMatchInfo>(
LoadNativeContext(context)
.elements[NativeContextSlot::REGEXP_LAST_MATCH_INFO_INDEX]);
} }
macro GetStrictArgumentsMap(implicit context: Context)(): Map { macro GetStrictArgumentsMap(implicit context: Context)(): Map {
return *NativeContextSlot(ContextSlot::STRICT_ARGUMENTS_MAP_INDEX); return UnsafeCast<Map>(
LoadNativeContext(context)
.elements[NativeContextSlot::STRICT_ARGUMENTS_MAP_INDEX]);
} }
macro GetSloppyArgumentsMap(implicit context: Context)(): Map { macro GetSloppyArgumentsMap(implicit context: Context)(): Map {
return *NativeContextSlot(ContextSlot::SLOPPY_ARGUMENTS_MAP_INDEX); return UnsafeCast<Map>(
LoadNativeContext(context)
.elements[NativeContextSlot::SLOPPY_ARGUMENTS_MAP_INDEX]);
} }
macro GetFastAliasedArgumentsMap(implicit context: Context)(): Map { macro GetFastAliasedArgumentsMap(implicit context: Context)(): Map {
return *NativeContextSlot(ContextSlot::FAST_ALIASED_ARGUMENTS_MAP_INDEX); return UnsafeCast<Map>(
LoadNativeContext(context)
.elements[NativeContextSlot::FAST_ALIASED_ARGUMENTS_MAP_INDEX]);
} }
macro GetWeakCellMap(implicit context: Context)(): Map { macro GetWeakCellMap(implicit context: Context)(): Map {
return %GetClassMapConstant<WeakCell>(); return %GetClassMapConstant<WeakCell>();
......
...@@ -62,10 +62,9 @@ TNode<JSProxy> ProxiesCodeStubAssembler::AllocateProxy( ...@@ -62,10 +62,9 @@ TNode<JSProxy> ProxiesCodeStubAssembler::AllocateProxy(
TNode<Context> ProxiesCodeStubAssembler::CreateProxyRevokeFunctionContext( TNode<Context> ProxiesCodeStubAssembler::CreateProxyRevokeFunctionContext(
TNode<JSProxy> proxy, TNode<NativeContext> native_context) { TNode<JSProxy> proxy, TNode<NativeContext> native_context) {
const TNode<Context> context = AllocateSyntheticFunctionContext( const TNode<Context> context =
native_context, ProxyRevokeFunctionContextSlot::kProxyContextLength); AllocateSyntheticFunctionContext(native_context, kProxyContextLength);
StoreContextElementNoWriteBarrier( StoreContextElementNoWriteBarrier(context, kProxySlot, proxy);
context, ProxyRevokeFunctionContextSlot::kProxySlot, proxy);
return context; return context;
} }
......
...@@ -33,6 +33,7 @@ class ProxiesCodeStubAssembler : public CodeStubAssembler { ...@@ -33,6 +33,7 @@ class ProxiesCodeStubAssembler : public CodeStubAssembler {
void CheckDeleteTrapResult(TNode<Context> context, TNode<JSReceiver> target, void CheckDeleteTrapResult(TNode<Context> context, TNode<JSReceiver> target,
TNode<JSProxy> proxy, TNode<Name> name); TNode<JSProxy> proxy, TNode<Name> name);
protected:
enum ProxyRevokeFunctionContextSlot { enum ProxyRevokeFunctionContextSlot {
kProxySlot = Context::MIN_CONTEXT_SLOTS, kProxySlot = Context::MIN_CONTEXT_SLOTS,
kProxyContextLength, kProxyContextLength,
......
...@@ -611,35 +611,6 @@ Cast<JSFunction|JSBoundFunction>(implicit context: Context)(o: Object): ...@@ -611,35 +611,6 @@ Cast<JSFunction|JSBoundFunction>(implicit context: Context)(o: Object):
} }
} }
Cast<FixedArray|Undefined>(o: HeapObject): FixedArray|
Undefined labels CastError {
typeswitch (o) {
case (o: Undefined): {
return o;
}
case (o: FixedArray): {
return o;
}
case (Object): {
goto CastError;
}
}
}
Cast<JSProxy|Null>(o: HeapObject): JSProxy|Null labels CastError {
typeswitch (o) {
case (o: Null): {
return o;
}
case (o: JSProxy): {
return o;
}
case (Object): {
goto CastError;
}
}
}
macro Is<A : type extends Object, B : type extends Object>( macro Is<A : type extends Object, B : type extends Object>(
implicit context: Context)(o: B): bool { implicit context: Context)(o: B): bool {
Cast<A>(o) otherwise return false; Cast<A>(o) otherwise return false;
......
...@@ -112,7 +112,7 @@ transitioning builtin ToObject(implicit context: Context)(input: JSAny): ...@@ -112,7 +112,7 @@ transitioning builtin ToObject(implicit context: Context)(input: JSAny):
try { try {
typeswitch (input) { typeswitch (input) {
case (Smi): { case (Smi): {
goto WrapPrimitive(ContextSlot::NUMBER_FUNCTION_INDEX); goto WrapPrimitive(NativeContextSlot::NUMBER_FUNCTION_INDEX);
} }
case (o: JSReceiver): { case (o: JSReceiver): {
return o; return o;
...@@ -120,14 +120,14 @@ transitioning builtin ToObject(implicit context: Context)(input: JSAny): ...@@ -120,14 +120,14 @@ transitioning builtin ToObject(implicit context: Context)(input: JSAny):
case (o: JSAnyNotSmi): { case (o: JSAnyNotSmi): {
const index: intptr = Convert<intptr>( const index: intptr = Convert<intptr>(
o.map.in_object_properties_start_or_constructor_function_index); o.map.in_object_properties_start_or_constructor_function_index);
if (index != kNoConstructorFunctionIndex) if (index != kNoConstructorFunctionIndex) goto WrapPrimitive(index);
goto WrapPrimitive(
%RawDownCast<Slot<NativeContext, JSFunction>>(index));
ThrowTypeError(MessageTemplate::kUndefinedOrNullToObject, 'ToObject'); ThrowTypeError(MessageTemplate::kUndefinedOrNullToObject, 'ToObject');
} }
} }
} label WrapPrimitive(constructorIndex: Slot<NativeContext, JSFunction>) { } label WrapPrimitive(constructorIndex: intptr) {
const constructor = *NativeContextSlot(constructorIndex); const nativeContext = LoadNativeContext(context);
const constructor =
UnsafeCast<JSFunction>(nativeContext.elements[constructorIndex]);
const map: Map = UnsafeCast<Map>(constructor.prototype_or_initial_map); const map: Map = UnsafeCast<Map>(constructor.prototype_or_initial_map);
const wrapper = const wrapper =
UnsafeCast<JSPrimitiveWrapper>(AllocateFastOrSlowJSObjectFromMap(map)); UnsafeCast<JSPrimitiveWrapper>(AllocateFastOrSlowJSObjectFromMap(map));
......
...@@ -66,12 +66,14 @@ FastFunctionPrototypeBind( ...@@ -66,12 +66,14 @@ FastFunctionPrototypeBind(
// Choose the right bound function map based on whether the target is // Choose the right bound function map based on whether the target is
// constructable. // constructable.
const boundFunctionMap: Map = const boundFunctionMap: Map = UnsafeCast<Map>(
IsConstructor(fn) ? IsConstructor(fn) ?
*NativeContextSlot( context
ContextSlot::BOUND_FUNCTION_WITH_CONSTRUCTOR_MAP_INDEX) : .elements[NativeContextSlot::
*NativeContextSlot(ContextSlot:: BOUND_FUNCTION_WITH_CONSTRUCTOR_MAP_INDEX] :
BOUND_FUNCTION_WITHOUT_CONSTRUCTOR_MAP_INDEX); context.elements
[NativeContextSlot::
BOUND_FUNCTION_WITHOUT_CONSTRUCTOR_MAP_INDEX]);
// Verify that prototype matches that of the target bound function. // Verify that prototype matches that of the target bound function.
......
...@@ -437,16 +437,19 @@ extern macro RefillMathRandom(NativeContext): Smi; ...@@ -437,16 +437,19 @@ extern macro RefillMathRandom(NativeContext): Smi;
transitioning javascript builtin transitioning javascript builtin
MathRandom(js-implicit context: NativeContext, receiver: JSAny)(): Number { MathRandom(js-implicit context: NativeContext, receiver: JSAny)(): Number {
let smiIndex: Smi = *NativeContextSlot(ContextSlot::MATH_RANDOM_INDEX_INDEX); let smiIndex: Smi =
Cast<Smi>(context.elements[NativeContextSlot::MATH_RANDOM_INDEX_INDEX])
otherwise unreachable;
if (smiIndex == 0) { if (smiIndex == 0) {
// refill math random. // refill math random.
smiIndex = RefillMathRandom(context); smiIndex = RefillMathRandom(context);
} }
const newSmiIndex: Smi = smiIndex - 1; const newSmiIndex: Smi = smiIndex - 1;
*NativeContextSlot(ContextSlot::MATH_RANDOM_INDEX_INDEX) = newSmiIndex; context.elements[NativeContextSlot::MATH_RANDOM_INDEX_INDEX] = newSmiIndex;
const array: FixedDoubleArray = const array: FixedDoubleArray = Cast<FixedDoubleArray>(
*NativeContextSlot(ContextSlot::MATH_RANDOM_CACHE_INDEX); context.elements[NativeContextSlot::MATH_RANDOM_CACHE_INDEX])
otherwise unreachable;
const random: float64 = const random: float64 =
array.floats[Convert<intptr>(newSmiIndex)].ValueUnsafeAssumeNotHole(); array.floats[Convert<intptr>(newSmiIndex)].ValueUnsafeAssumeNotHole();
return AllocateHeapNumberWithValue(random); return AllocateHeapNumberWithValue(random);
......
...@@ -92,19 +92,22 @@ ObjectSetPrototypeOfDontThrow(implicit context: Context)( ...@@ -92,19 +92,22 @@ ObjectSetPrototypeOfDontThrow(implicit context: Context)(
transitioning builtin CreateObjectWithoutProperties(implicit context: Context)( transitioning builtin CreateObjectWithoutProperties(implicit context: Context)(
prototype: JSAny): JSAny { prototype: JSAny): JSAny {
const nativeContext = LoadNativeContext(context);
try { try {
let map: Map; let map: Map;
let properties: NameDictionary|EmptyFixedArray; let properties: NameDictionary|EmptyFixedArray;
typeswitch (prototype) { typeswitch (prototype) {
case (Null): { case (Null): {
map = *NativeContextSlot( map = UnsafeCast<Map>(
ContextSlot::SLOW_OBJECT_WITH_NULL_PROTOTYPE_MAP); nativeContext.elements
[NativeContextSlot::SLOW_OBJECT_WITH_NULL_PROTOTYPE_MAP]);
properties = AllocateNameDictionary(kNameDictionaryInitialCapacity); properties = AllocateNameDictionary(kNameDictionaryInitialCapacity);
} }
case (prototype: JSReceiver): { case (prototype: JSReceiver): {
properties = kEmptyFixedArray; properties = kEmptyFixedArray;
const objectFunction = const objectFunction = UnsafeCast<JSFunction>(
*NativeContextSlot(ContextSlot::OBJECT_FUNCTION_INDEX); nativeContext.elements[NativeContextSlot::OBJECT_FUNCTION_INDEX]);
map = UnsafeCast<Map>(objectFunction.prototype_or_initial_map); map = UnsafeCast<Map>(objectFunction.prototype_or_initial_map);
if (prototype != map.prototype) { if (prototype != map.prototype) {
const prototypeInfo = prototype.map.PrototypeInfo() otherwise Runtime; const prototypeInfo = prototype.map.PrototypeInfo() otherwise Runtime;
......
...@@ -35,7 +35,7 @@ const kResolveString: String = ResolveStringConstant(); ...@@ -35,7 +35,7 @@ const kResolveString: String = ResolveStringConstant();
extern macro IsPromiseResolveProtectorCellInvalid(): bool; extern macro IsPromiseResolveProtectorCellInvalid(): bool;
extern macro AllocateFunctionWithMapAndContext( extern macro AllocateFunctionWithMapAndContext(
Map, SharedFunctionInfo, FunctionContext): JSFunction; Map, SharedFunctionInfo, Context): JSFunction;
extern macro PromiseReactionMapConstant(): Map; extern macro PromiseReactionMapConstant(): Map;
extern macro PromiseFulfillReactionJobTaskMapConstant(): Map; extern macro PromiseFulfillReactionJobTaskMapConstant(): Map;
...@@ -252,33 +252,24 @@ RejectPromise(implicit context: Context)( ...@@ -252,33 +252,24 @@ RejectPromise(implicit context: Context)(
const kPromiseCapabilitySize: const kPromiseCapabilitySize:
constexpr int31 generates 'PromiseCapability::kSize'; constexpr int31 generates 'PromiseCapability::kSize';
const kPromiseBuiltinsCapabilitiesContextLength: constexpr int31
type PromiseResolvingFunctionContext extends FunctionContext; generates 'PromiseBuiltins::kCapabilitiesContextLength';
extern enum PromiseResolvingFunctionContextSlot extends intptr const kPromiseBuiltinsCapabilitySlot: constexpr ContextSlot
constexpr 'PromiseBuiltins::PromiseResolvingFunctionContextSlot' { generates 'PromiseBuiltins::kCapabilitySlot';
kPromiseSlot: Slot<PromiseResolvingFunctionContext, JSPromise>, const kPromiseBuiltinsPromiseSlot: constexpr ContextSlot
kAlreadyResolvedSlot: Slot<PromiseResolvingFunctionContext, Boolean>, generates 'PromiseBuiltins::kPromiseSlot';
kDebugEventSlot: Slot<PromiseResolvingFunctionContext, Boolean>, const kPromiseBuiltinsAlreadyResolvedSlot: constexpr ContextSlot
kPromiseContextLength generates 'PromiseBuiltins::kAlreadyResolvedSlot';
} const kPromiseBuiltinsDebugEventSlot: constexpr ContextSlot
generates 'PromiseBuiltins::kDebugEventSlot';
type PromiseCapabilitiesExecutorContext extends FunctionContext;
extern enum FunctionContextSlot extends intptr
constexpr 'PromiseBuiltins::FunctionContextSlot' {
kCapabilitySlot: Slot<PromiseCapabilitiesExecutorContext, PromiseCapability>,
kCapabilitiesContextLength
}
@export @export
macro CreatePromiseCapabilitiesExecutorContext( macro CreatePromiseCapabilitiesExecutorContext(
nativeContext: NativeContext, capability: PromiseCapability): nativeContext: NativeContext, capability: PromiseCapability): Context {
PromiseCapabilitiesExecutorContext { const executorContext = AllocateSyntheticFunctionContext(
const executorContext = %RawDownCast<PromiseCapabilitiesExecutorContext>( nativeContext, kPromiseBuiltinsCapabilitiesContextLength);
AllocateSyntheticFunctionContext(
nativeContext, FunctionContextSlot::kCapabilitiesContextLength)); executorContext.elements[kPromiseBuiltinsCapabilitySlot] = capability;
InitContextSlot(
executorContext, FunctionContextSlot::kCapabilitySlot, capability);
return executorContext; return executorContext;
} }
...@@ -302,12 +293,13 @@ struct PromiseResolvingFunctions { ...@@ -302,12 +293,13 @@ struct PromiseResolvingFunctions {
@export @export
macro CreatePromiseResolvingFunctions(implicit context: Context)( macro CreatePromiseResolvingFunctions(implicit context: Context)(
promise: JSPromise, debugEvent: Boolean, nativeContext: NativeContext): promise: JSPromise, debugEvent: Object, nativeContext: NativeContext):
PromiseResolvingFunctions { PromiseResolvingFunctions {
const promiseContext = CreatePromiseResolvingFunctionsContext( const promiseContext = CreatePromiseResolvingFunctionsContext(
promise, debugEvent, nativeContext); promise, debugEvent, nativeContext);
const map = *NativeContextSlot( const map = UnsafeCast<Map>(
nativeContext, ContextSlot::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX); nativeContext.elements
[NativeContextSlot::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX]);
const resolveInfo = PromiseCapabilityDefaultResolveSharedFunConstant(); const resolveInfo = PromiseCapabilityDefaultResolveSharedFunConstant();
const resolve: JSFunction = const resolve: JSFunction =
...@@ -320,10 +312,11 @@ macro CreatePromiseResolvingFunctions(implicit context: Context)( ...@@ -320,10 +312,11 @@ macro CreatePromiseResolvingFunctions(implicit context: Context)(
transitioning macro transitioning macro
InnerNewPromiseCapability(implicit context: Context)( InnerNewPromiseCapability(implicit context: Context)(
constructor: HeapObject, debugEvent: Boolean): PromiseCapability { constructor: HeapObject, debugEvent: Object): PromiseCapability {
const nativeContext = LoadNativeContext(context); const nativeContext = LoadNativeContext(context);
if (constructor == if (TaggedEqual(
*NativeContextSlot(nativeContext, ContextSlot::PROMISE_FUNCTION_INDEX)) { constructor,
nativeContext.elements[NativeContextSlot::PROMISE_FUNCTION_INDEX])) {
const promise = NewJSPromise(); const promise = NewJSPromise();
const pair = const pair =
...@@ -338,10 +331,9 @@ InnerNewPromiseCapability(implicit context: Context)( ...@@ -338,10 +331,9 @@ InnerNewPromiseCapability(implicit context: Context)(
CreatePromiseCapabilitiesExecutorContext(nativeContext, capability); CreatePromiseCapabilitiesExecutorContext(nativeContext, capability);
const executorInfo = PromiseGetCapabilitiesExecutorSharedFunConstant(); const executorInfo = PromiseGetCapabilitiesExecutorSharedFunConstant();
const functionMap = const functionMap = UnsafeCast<Map>(
*NativeContextSlot( nativeContext.elements
nativeContext, [NativeContextSlot::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX]);
ContextSlot::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
const executor = AllocateFunctionWithMapAndContext( const executor = AllocateFunctionWithMapAndContext(
functionMap, executorInfo, executorContext); functionMap, executorInfo, executorContext);
...@@ -359,7 +351,7 @@ InnerNewPromiseCapability(implicit context: Context)( ...@@ -359,7 +351,7 @@ InnerNewPromiseCapability(implicit context: Context)(
// https://tc39.es/ecma262/#sec-newpromisecapability // https://tc39.es/ecma262/#sec-newpromisecapability
transitioning builtin transitioning builtin
NewPromiseCapability(implicit context: Context)( NewPromiseCapability(implicit context: Context)(
maybeConstructor: Object, debugEvent: Boolean): PromiseCapability { maybeConstructor: Object, debugEvent: Object): PromiseCapability {
typeswitch (maybeConstructor) { typeswitch (maybeConstructor) {
case (Smi): { case (Smi): {
ThrowTypeError(MessageTemplate::kNotConstructor, maybeConstructor); ThrowTypeError(MessageTemplate::kNotConstructor, maybeConstructor);
...@@ -376,15 +368,14 @@ NewPromiseCapability(implicit context: Context)( ...@@ -376,15 +368,14 @@ NewPromiseCapability(implicit context: Context)(
// https://tc39.es/ecma262/#sec-promise-reject-functions // https://tc39.es/ecma262/#sec-promise-reject-functions
transitioning javascript builtin transitioning javascript builtin
PromiseCapabilityDefaultReject( PromiseCapabilityDefaultReject(
js-implicit context: Context, receiver: JSAny)(reason: JSAny): JSAny { js-implicit context: NativeContext, receiver: JSAny)(reason: JSAny): JSAny {
const context = %RawDownCast<PromiseResolvingFunctionContext>(context);
// 2. Let promise be F.[[Promise]]. // 2. Let promise be F.[[Promise]].
const promise = const promise =
*ContextSlot(context, PromiseResolvingFunctionContextSlot::kPromiseSlot); UnsafeCast<JSPromise>(context.elements[kPromiseBuiltinsPromiseSlot]);
// 3. Let alreadyResolved be F.[[AlreadyResolved]]. // 3. Let alreadyResolved be F.[[AlreadyResolved]].
const alreadyResolved = *ContextSlot( const alreadyResolved = UnsafeCast<Boolean>(
context, PromiseResolvingFunctionContextSlot::kAlreadyResolvedSlot); context.elements[kPromiseBuiltinsAlreadyResolvedSlot]);
// 4. If alreadyResolved.[[Value]] is true, return undefined. // 4. If alreadyResolved.[[Value]] is true, return undefined.
if (alreadyResolved == True) { if (alreadyResolved == True) {
...@@ -392,28 +383,26 @@ PromiseCapabilityDefaultReject( ...@@ -392,28 +383,26 @@ PromiseCapabilityDefaultReject(
} }
// 5. Set alreadyResolved.[[Value]] to true. // 5. Set alreadyResolved.[[Value]] to true.
*ContextSlot( context.elements[kPromiseBuiltinsAlreadyResolvedSlot] = True;
context, PromiseResolvingFunctionContextSlot::kAlreadyResolvedSlot) =
True;
// 6. Return RejectPromise(promise, reason). // 6. Return RejectPromise(promise, reason).
const debugEvent = *ContextSlot( const debugEvent =
context, PromiseResolvingFunctionContextSlot::kDebugEventSlot); UnsafeCast<Boolean>(context.elements[kPromiseBuiltinsDebugEventSlot]);
return RejectPromise(promise, reason, debugEvent); return RejectPromise(promise, reason, debugEvent);
} }
// https://tc39.es/ecma262/#sec-promise-resolve-functions // https://tc39.es/ecma262/#sec-promise-resolve-functions
transitioning javascript builtin transitioning javascript builtin
PromiseCapabilityDefaultResolve( PromiseCapabilityDefaultResolve(
js-implicit context: Context, receiver: JSAny)(resolution: JSAny): JSAny { js-implicit context: NativeContext,
const context = %RawDownCast<PromiseResolvingFunctionContext>(context); receiver: JSAny)(resolution: JSAny): JSAny {
// 2. Let promise be F.[[Promise]]. // 2. Let promise be F.[[Promise]].
const promise: JSPromise = const promise =
*ContextSlot(context, PromiseResolvingFunctionContextSlot::kPromiseSlot); UnsafeCast<JSPromise>(context.elements[kPromiseBuiltinsPromiseSlot]);
// 3. Let alreadyResolved be F.[[AlreadyResolved]]. // 3. Let alreadyResolved be F.[[AlreadyResolved]].
const alreadyResolved: Boolean = *ContextSlot( const alreadyResolved = UnsafeCast<Boolean>(
context, PromiseResolvingFunctionContextSlot::kAlreadyResolvedSlot); context.elements[kPromiseBuiltinsAlreadyResolvedSlot]);
// 4. If alreadyResolved.[[Value]] is true, return undefined. // 4. If alreadyResolved.[[Value]] is true, return undefined.
if (alreadyResolved == True) { if (alreadyResolved == True) {
...@@ -421,9 +410,7 @@ PromiseCapabilityDefaultResolve( ...@@ -421,9 +410,7 @@ PromiseCapabilityDefaultResolve(
} }
// 5. Set alreadyResolved.[[Value]] to true. // 5. Set alreadyResolved.[[Value]] to true.
*ContextSlot( context.elements[kPromiseBuiltinsAlreadyResolvedSlot] = True;
context, PromiseResolvingFunctionContextSlot::kAlreadyResolvedSlot) =
True;
// The rest of the logic (and the catch prediction) is // The rest of the logic (and the catch prediction) is
// encapsulated in the dedicated ResolvePromise builtin. // encapsulated in the dedicated ResolvePromise builtin.
...@@ -490,7 +477,8 @@ PromiseReject( ...@@ -490,7 +477,8 @@ PromiseReject(
const receiver = Cast<JSReceiver>(receiver) otherwise const receiver = Cast<JSReceiver>(receiver) otherwise
ThrowTypeError(MessageTemplate::kCalledOnNonObject, 'PromiseReject'); ThrowTypeError(MessageTemplate::kCalledOnNonObject, 'PromiseReject');
const promiseFun = *NativeContextSlot(ContextSlot::PROMISE_FUNCTION_INDEX); const promiseFun =
context.elements[NativeContextSlot::PROMISE_FUNCTION_INDEX];
if (promiseFun == receiver) { if (promiseFun == receiver) {
const promise = NewJSPromise(PromiseState::kRejected, reason); const promise = NewJSPromise(PromiseState::kRejected, reason);
runtime::PromiseRejectEventFromStack(promise, reason); runtime::PromiseRejectEventFromStack(promise, reason);
...@@ -513,11 +501,11 @@ const kPromiseExecutorAlreadyInvoked: constexpr MessageTemplate ...@@ -513,11 +501,11 @@ const kPromiseExecutorAlreadyInvoked: constexpr MessageTemplate
// https://tc39.es/ecma262/#sec-getcapabilitiesexecutor-functions // https://tc39.es/ecma262/#sec-getcapabilitiesexecutor-functions
transitioning javascript builtin transitioning javascript builtin
PromiseGetCapabilitiesExecutor(js-implicit context: Context, receiver: JSAny)( PromiseGetCapabilitiesExecutor(
js-implicit context: NativeContext, receiver: JSAny)(
resolve: JSAny, reject: JSAny): JSAny { resolve: JSAny, reject: JSAny): JSAny {
const context = %RawDownCast<PromiseCapabilitiesExecutorContext>(context); const capability = UnsafeCast<PromiseCapability>(
const capability: PromiseCapability = context.elements[kPromiseBuiltinsCapabilitySlot]);
*ContextSlot(context, FunctionContextSlot::kCapabilitySlot);
if (capability.resolve != Undefined || capability.reject != Undefined) if (capability.resolve != Undefined || capability.reject != Undefined)
deferred { deferred {
ThrowTypeError(kPromiseExecutorAlreadyInvoked); ThrowTypeError(kPromiseExecutorAlreadyInvoked);
...@@ -531,8 +519,8 @@ PromiseGetCapabilitiesExecutor(js-implicit context: Context, receiver: JSAny)( ...@@ -531,8 +519,8 @@ PromiseGetCapabilitiesExecutor(js-implicit context: Context, receiver: JSAny)(
macro IsPromiseResolveLookupChainIntact(implicit context: Context)( macro IsPromiseResolveLookupChainIntact(implicit context: Context)(
nativeContext: NativeContext, constructor: JSReceiver): bool { nativeContext: NativeContext, constructor: JSReceiver): bool {
if (IsForceSlowPath()) return false; if (IsForceSlowPath()) return false;
const promiseFun = const promiseFun = UnsafeCast<JSFunction>(
*NativeContextSlot(nativeContext, ContextSlot::PROMISE_FUNCTION_INDEX); nativeContext.elements[NativeContextSlot::PROMISE_FUNCTION_INDEX]);
return promiseFun == constructor && !IsPromiseResolveProtectorCellInvalid(); return promiseFun == constructor && !IsPromiseResolveProtectorCellInvalid();
} }
......
...@@ -21,8 +21,8 @@ struct PromiseAllSettledWrapResultAsFulfilledFunctor { ...@@ -21,8 +21,8 @@ struct PromiseAllSettledWrapResultAsFulfilledFunctor {
// TODO(gsathya): Optimize the creation using a cached map to // TODO(gsathya): Optimize the creation using a cached map to
// prevent transitions here. // prevent transitions here.
// 9. Let obj be ! ObjectCreate(%ObjectPrototype%). // 9. Let obj be ! ObjectCreate(%ObjectPrototype%).
const objectFunction = const objectFunction = UnsafeCast<JSFunction>(
*NativeContextSlot(nativeContext, ContextSlot::OBJECT_FUNCTION_INDEX); nativeContext.elements[NativeContextSlot::OBJECT_FUNCTION_INDEX]);
const objectFunctionMap = const objectFunctionMap =
UnsafeCast<Map>(objectFunction.prototype_or_initial_map); UnsafeCast<Map>(objectFunction.prototype_or_initial_map);
const obj = AllocateJSObjectFromMap(objectFunctionMap); const obj = AllocateJSObjectFromMap(objectFunctionMap);
...@@ -44,8 +44,8 @@ struct PromiseAllSettledWrapResultAsRejectedFunctor { ...@@ -44,8 +44,8 @@ struct PromiseAllSettledWrapResultAsRejectedFunctor {
// TODO(gsathya): Optimize the creation using a cached map to // TODO(gsathya): Optimize the creation using a cached map to
// prevent transitions here. // prevent transitions here.
// 9. Let obj be ! ObjectCreate(%ObjectPrototype%). // 9. Let obj be ! ObjectCreate(%ObjectPrototype%).
const objectFunction = const objectFunction = UnsafeCast<JSFunction>(
*NativeContextSlot(nativeContext, ContextSlot::OBJECT_FUNCTION_INDEX); nativeContext.elements[NativeContextSlot::OBJECT_FUNCTION_INDEX]);
const objectFunctionMap = const objectFunctionMap =
UnsafeCast<Map>(objectFunction.prototype_or_initial_map); UnsafeCast<Map>(objectFunction.prototype_or_initial_map);
const obj = AllocateJSObjectFromMap(objectFunctionMap); const obj = AllocateJSObjectFromMap(objectFunctionMap);
...@@ -62,15 +62,11 @@ struct PromiseAllSettledWrapResultAsRejectedFunctor { ...@@ -62,15 +62,11 @@ struct PromiseAllSettledWrapResultAsRejectedFunctor {
extern macro LoadJSReceiverIdentityHash(Object): intptr labels IfNoHash; extern macro LoadJSReceiverIdentityHash(Object): intptr labels IfNoHash;
type PromiseAllResolveElementContext extends FunctionContext; extern enum PromiseAllResolveElementContextSlots extends int31
extern enum PromiseAllResolveElementContextSlots extends intptr
constexpr 'PromiseBuiltins::PromiseAllResolveElementContextSlots' { constexpr 'PromiseBuiltins::PromiseAllResolveElementContextSlots' {
kPromiseAllResolveElementRemainingSlot: kPromiseAllResolveElementRemainingSlot,
Slot<PromiseAllResolveElementContext, Smi>, kPromiseAllResolveElementCapabilitySlot,
kPromiseAllResolveElementCapabilitySlot: kPromiseAllResolveElementValuesSlot,
Slot<PromiseAllResolveElementContext, PromiseCapability>,
kPromiseAllResolveElementValuesSlot:
Slot<PromiseAllResolveElementContext, FixedArray>,
kPromiseAllResolveElementLength kPromiseAllResolveElementLength
} }
extern operator '[]=' macro StoreContextElement( extern operator '[]=' macro StoreContextElement(
...@@ -85,7 +81,7 @@ const kPropertyArrayHashFieldMax: constexpr int31 ...@@ -85,7 +81,7 @@ const kPropertyArrayHashFieldMax: constexpr int31
generates 'PropertyArray::HashField::kMax'; generates 'PropertyArray::HashField::kMax';
transitioning macro PromiseAllResolveElementClosure<F: type>( transitioning macro PromiseAllResolveElementClosure<F: type>(
implicit context: PromiseAllResolveElementContext|NativeContext)( implicit context: Context)(
value: JSAny, function: JSFunction, wrapResultFunctor: F, value: JSAny, function: JSFunction, wrapResultFunctor: F,
hasResolveAndRejectClosures: constexpr bool): JSAny { hasResolveAndRejectClosures: constexpr bool): JSAny {
// We use the {function}s context as the marker to remember whether this // We use the {function}s context as the marker to remember whether this
...@@ -93,21 +89,14 @@ transitioning macro PromiseAllResolveElementClosure<F: type>( ...@@ -93,21 +89,14 @@ transitioning macro PromiseAllResolveElementClosure<F: type>(
// element context (which is a FunctionContext) until it was called the // element context (which is a FunctionContext) until it was called the
// first time, in which case we make it point to the native context here // first time, in which case we make it point to the native context here
// to mark this resolve element closure as done. // to mark this resolve element closure as done.
let promiseContext: PromiseAllResolveElementContext; if (IsNativeContext(context)) deferred {
typeswitch (context) {
case (NativeContext): deferred {
return Undefined; return Undefined;
} }
case (context: PromiseAllResolveElementContext): {
promiseContext = context;
}
}
assert( assert(
promiseContext.length == context.length ==
SmiTag(PromiseAllResolveElementContextSlots:: PromiseAllResolveElementContextSlots::kPromiseAllResolveElementLength);
kPromiseAllResolveElementLength)); const nativeContext = LoadNativeContext(context);
const nativeContext = LoadNativeContext(promiseContext);
function.context = nativeContext; function.context = nativeContext;
// Determine the index from the {function}. // Determine the index from the {function}.
...@@ -117,23 +106,19 @@ transitioning macro PromiseAllResolveElementClosure<F: type>( ...@@ -117,23 +106,19 @@ transitioning macro PromiseAllResolveElementClosure<F: type>(
assert(identityHash > 0); assert(identityHash > 0);
const index = identityHash - 1; const index = identityHash - 1;
let remainingElementsCount = *ContextSlot( let remainingElementsCount = UnsafeCast<Smi>(
promiseContext, context.elements[PromiseAllResolveElementContextSlots::
PromiseAllResolveElementContextSlots:: kPromiseAllResolveElementRemainingSlot]);
kPromiseAllResolveElementRemainingSlot);
let values = *ContextSlot( let values = UnsafeCast<FixedArray>(
promiseContext, context.elements[PromiseAllResolveElementContextSlots::
PromiseAllResolveElementContextSlots:: kPromiseAllResolveElementValuesSlot]);
kPromiseAllResolveElementValuesSlot);
const newCapacity = index + 1; const newCapacity = index + 1;
if (newCapacity > values.length_intptr) deferred { if (newCapacity > values.length_intptr) deferred {
// This happens only when the promises are resolved during iteration. // This happens only when the promises are resolved during iteration.
values = ExtractFixedArray(values, 0, values.length_intptr, newCapacity); values = ExtractFixedArray(values, 0, values.length_intptr, newCapacity);
*ContextSlot( context.elements[PromiseAllResolveElementContextSlots::
promiseContext, kPromiseAllResolveElementValuesSlot] = values;
PromiseAllResolveElementContextSlots::
kPromiseAllResolveElementValuesSlot) = values;
} }
// Promise.allSettled, for each input element, has both a resolve and a reject // Promise.allSettled, for each input element, has both a resolve and a reject
...@@ -159,21 +144,19 @@ transitioning macro PromiseAllResolveElementClosure<F: type>( ...@@ -159,21 +144,19 @@ transitioning macro PromiseAllResolveElementClosure<F: type>(
values.objects[index] = updatedValue; values.objects[index] = updatedValue;
remainingElementsCount = remainingElementsCount - 1; remainingElementsCount = remainingElementsCount - 1;
*ContextSlot( context.elements[PromiseAllResolveElementContextSlots::
promiseContext, kPromiseAllResolveElementRemainingSlot] =
PromiseAllResolveElementContextSlots:: remainingElementsCount;
kPromiseAllResolveElementRemainingSlot) = remainingElementsCount;
if (remainingElementsCount == 0) { if (remainingElementsCount == 0) {
const capability = *ContextSlot( const capability = UnsafeCast<PromiseCapability>(
promiseContext, context.elements[PromiseAllResolveElementContextSlots::
PromiseAllResolveElementContextSlots:: kPromiseAllResolveElementCapabilitySlot]);
kPromiseAllResolveElementCapabilitySlot);
const resolve = UnsafeCast<JSAny>(capability.resolve); const resolve = UnsafeCast<JSAny>(capability.resolve);
const arrayMap = const arrayMap = UnsafeCast<Map>(
*NativeContextSlot( nativeContext
nativeContext, ContextSlot::JS_ARRAY_PACKED_ELEMENTS_MAP_INDEX); .elements[NativeContextSlot::JS_ARRAY_PACKED_ELEMENTS_MAP_INDEX]);
const valuesArray = NewJSArray(arrayMap, values); const valuesArray = NewJSArray(arrayMap, values);
Call(promiseContext, resolve, Undefined, valuesArray); Call(context, resolve, Undefined, valuesArray);
} }
return Undefined; return Undefined;
} }
...@@ -182,8 +165,6 @@ transitioning javascript builtin ...@@ -182,8 +165,6 @@ transitioning javascript builtin
PromiseAllResolveElementClosure( PromiseAllResolveElementClosure(
js-implicit context: Context, receiver: JSAny, js-implicit context: Context, receiver: JSAny,
target: JSFunction)(value: JSAny): JSAny { target: JSFunction)(value: JSAny): JSAny {
const context =
%RawDownCast<PromiseAllResolveElementContext|NativeContext>(context);
return PromiseAllResolveElementClosure( return PromiseAllResolveElementClosure(
value, target, PromiseAllWrapResultAsFulfilledFunctor{}, false); value, target, PromiseAllWrapResultAsFulfilledFunctor{}, false);
} }
...@@ -192,8 +173,6 @@ transitioning javascript builtin ...@@ -192,8 +173,6 @@ transitioning javascript builtin
PromiseAllSettledResolveElementClosure( PromiseAllSettledResolveElementClosure(
js-implicit context: Context, receiver: JSAny, js-implicit context: Context, receiver: JSAny,
target: JSFunction)(value: JSAny): JSAny { target: JSFunction)(value: JSAny): JSAny {
const context =
%RawDownCast<PromiseAllResolveElementContext|NativeContext>(context);
return PromiseAllResolveElementClosure( return PromiseAllResolveElementClosure(
value, target, PromiseAllSettledWrapResultAsFulfilledFunctor{}, true); value, target, PromiseAllSettledWrapResultAsFulfilledFunctor{}, true);
} }
...@@ -202,8 +181,6 @@ transitioning javascript builtin ...@@ -202,8 +181,6 @@ transitioning javascript builtin
PromiseAllSettledRejectElementClosure( PromiseAllSettledRejectElementClosure(
js-implicit context: Context, receiver: JSAny, js-implicit context: Context, receiver: JSAny,
target: JSFunction)(value: JSAny): JSAny { target: JSFunction)(value: JSAny): JSAny {
const context =
%RawDownCast<PromiseAllResolveElementContext|NativeContext>(context);
return PromiseAllResolveElementClosure( return PromiseAllResolveElementClosure(
value, target, PromiseAllSettledWrapResultAsRejectedFunctor{}, true); value, target, PromiseAllSettledWrapResultAsRejectedFunctor{}, true);
} }
......
This diff is collapsed.
...@@ -5,15 +5,11 @@ ...@@ -5,15 +5,11 @@
#include 'src/builtins/builtins-promise-gen.h' #include 'src/builtins/builtins-promise-gen.h'
namespace promise { namespace promise {
type PromiseAnyRejectElementContext extends FunctionContext; extern enum PromiseAnyRejectElementContextSlots extends int31
extern enum PromiseAnyRejectElementContextSlots extends intptr
constexpr 'PromiseBuiltins::PromiseAnyRejectElementContextSlots' { constexpr 'PromiseBuiltins::PromiseAnyRejectElementContextSlots' {
kPromiseAnyRejectElementRemainingSlot: kPromiseAnyRejectElementRemainingSlot,
Slot<PromiseAnyRejectElementContext, Smi>, kPromiseAnyRejectElementCapabilitySlot,
kPromiseAnyRejectElementCapabilitySlot: kPromiseAnyRejectElementErrorsSlot,
Slot<PromiseAnyRejectElementContext, PromiseCapability>,
kPromiseAnyRejectElementErrorsSlot:
Slot<PromiseAnyRejectElementContext, FixedArray>,
kPromiseAnyRejectElementLength kPromiseAnyRejectElementLength
} }
...@@ -31,36 +27,30 @@ extern operator '[]' macro LoadContextElement( ...@@ -31,36 +27,30 @@ extern operator '[]' macro LoadContextElement(
// case to mark it's done). See Promise.all which uses the same approach. // case to mark it's done). See Promise.all which uses the same approach.
transitioning macro CreatePromiseAnyRejectElementContext( transitioning macro CreatePromiseAnyRejectElementContext(
implicit context: Context)( implicit context: Context)(
capability: PromiseCapability, capability: PromiseCapability, nativeContext: NativeContext): Context {
nativeContext: NativeContext): PromiseAnyRejectElementContext { const rejectContext = AllocateSyntheticFunctionContext(
const rejectContext = %RawDownCast<PromiseAnyRejectElementContext>(
AllocateSyntheticFunctionContext(
nativeContext, nativeContext,
PromiseAnyRejectElementContextSlots::kPromiseAnyRejectElementLength)); PromiseAnyRejectElementContextSlots::kPromiseAnyRejectElementLength);
InitContextSlot( rejectContext.elements[PromiseAnyRejectElementContextSlots::
rejectContext, kPromiseAnyRejectElementRemainingSlot] =
PromiseAnyRejectElementContextSlots:: SmiConstant(1);
kPromiseAnyRejectElementRemainingSlot, rejectContext.elements[PromiseAnyRejectElementContextSlots::
1); kPromiseAnyRejectElementCapabilitySlot] =
InitContextSlot( capability;
rejectContext, rejectContext.elements[PromiseAnyRejectElementContextSlots::
PromiseAnyRejectElementContextSlots:: kPromiseAnyRejectElementErrorsSlot] =
kPromiseAnyRejectElementCapabilitySlot, kEmptyFixedArray;
capability);
InitContextSlot(
rejectContext,
PromiseAnyRejectElementContextSlots::kPromiseAnyRejectElementErrorsSlot,
kEmptyFixedArray);
return rejectContext; return rejectContext;
} }
macro CreatePromiseAnyRejectElementFunction(implicit context: Context)( macro CreatePromiseAnyRejectElementFunction(implicit context: Context)(
rejectElementContext: PromiseAnyRejectElementContext, index: Smi, rejectElementContext: Context, index: Smi,
nativeContext: NativeContext): JSFunction { nativeContext: NativeContext): JSFunction {
assert(index > 0); assert(index > 0);
assert(index < kPropertyArrayHashFieldMax); assert(index < kPropertyArrayHashFieldMax);
const map = *ContextSlot( const map = UnsafeCast<Map>(
nativeContext, ContextSlot::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX); nativeContext.elements
[NativeContextSlot::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX]);
const rejectInfo = PromiseAnyRejectElementSharedFunConstant(); const rejectInfo = PromiseAnyRejectElementSharedFunConstant();
const reject = const reject =
AllocateFunctionWithMapAndContext(map, rejectInfo, rejectElementContext); AllocateFunctionWithMapAndContext(map, rejectInfo, rejectElementContext);
...@@ -91,9 +81,7 @@ PromiseAnyRejectElementClosure( ...@@ -91,9 +81,7 @@ PromiseAnyRejectElementClosure(
assert( assert(
context.length == context.length ==
SmiTag( PromiseAnyRejectElementContextSlots::kPromiseAnyRejectElementLength);
PromiseAnyRejectElementContextSlots::kPromiseAnyRejectElementLength));
const context = %RawDownCast<PromiseAnyRejectElementContext>(context);
// 4. Set alreadyCalled.[[Value]] to true. // 4. Set alreadyCalled.[[Value]] to true.
const nativeContext = LoadNativeContext(context); const nativeContext = LoadNativeContext(context);
...@@ -106,36 +94,32 @@ PromiseAnyRejectElementClosure( ...@@ -106,36 +94,32 @@ PromiseAnyRejectElementClosure(
const index = identityHash - 1; const index = identityHash - 1;
// 6. Let errors be F.[[Errors]]. // 6. Let errors be F.[[Errors]].
let errors = *ContextSlot( let errors = UnsafeCast<FixedArray>(
context, context.elements[PromiseAnyRejectElementContextSlots::
PromiseAnyRejectElementContextSlots::kPromiseAnyRejectElementErrorsSlot); kPromiseAnyRejectElementErrorsSlot]);
// 7. Let promiseCapability be F.[[Capability]]. // 7. Let promiseCapability be F.[[Capability]].
// 8. Let remainingElementsCount be F.[[RemainingElements]]. // 8. Let remainingElementsCount be F.[[RemainingElements]].
let remainingElementsCount = *ContextSlot( let remainingElementsCount = UnsafeCast<Smi>(
context, context.elements[PromiseAnyRejectElementContextSlots::
PromiseAnyRejectElementContextSlots:: kPromiseAnyRejectElementRemainingSlot]);
kPromiseAnyRejectElementRemainingSlot);
// 9. Set errors[index] to x. // 9. Set errors[index] to x.
const newCapacity = IntPtrMax(SmiUntag(remainingElementsCount), index + 1); const newCapacity = IntPtrMax(SmiUntag(remainingElementsCount), index + 1);
if (newCapacity > errors.length_intptr) deferred { if (newCapacity > errors.length_intptr) deferred {
errors = ExtractFixedArray(errors, 0, errors.length_intptr, newCapacity); errors = ExtractFixedArray(errors, 0, errors.length_intptr, newCapacity);
*ContextSlot( context.elements[PromiseAnyRejectElementContextSlots::
context, kPromiseAnyRejectElementErrorsSlot] = errors;
PromiseAnyRejectElementContextSlots::
kPromiseAnyRejectElementErrorsSlot) = errors;
} }
errors.objects[index] = value; errors.objects[index] = value;
// 10. Set remainingElementsCount.[[Value]] to // 10. Set remainingElementsCount.[[Value]] to
// remainingElementsCount.[[Value]] - 1. // remainingElementsCount.[[Value]] - 1.
remainingElementsCount = remainingElementsCount - 1; remainingElementsCount = remainingElementsCount - 1;
*ContextSlot( context.elements[PromiseAnyRejectElementContextSlots::
context, kPromiseAnyRejectElementRemainingSlot] =
PromiseAnyRejectElementContextSlots:: remainingElementsCount;
kPromiseAnyRejectElementRemainingSlot) = remainingElementsCount;
// 11. If remainingElementsCount.[[Value]] is 0, then // 11. If remainingElementsCount.[[Value]] is 0, then
if (remainingElementsCount == 0) { if (remainingElementsCount == 0) {
...@@ -144,10 +128,9 @@ PromiseAnyRejectElementClosure( ...@@ -144,10 +128,9 @@ PromiseAnyRejectElementClosure(
// b. Set error.[[AggregateErrors]] to errors. // b. Set error.[[AggregateErrors]] to errors.
const error = ConstructAggregateError(errors); const error = ConstructAggregateError(errors);
// c. Return ? Call(promiseCapability.[[Reject]], undefined, « error »). // c. Return ? Call(promiseCapability.[[Reject]], undefined, « error »).
const capability = *ContextSlot( const capability = UnsafeCast<PromiseCapability>(
context, context.elements[PromiseAnyRejectElementContextSlots::
PromiseAnyRejectElementContextSlots:: kPromiseAnyRejectElementCapabilitySlot]);
kPromiseAnyRejectElementCapabilitySlot);
Call(context, UnsafeCast<Callable>(capability.reject), Undefined, error); Call(context, UnsafeCast<Callable>(capability.reject), Undefined, error);
} }
...@@ -175,8 +158,8 @@ Reject(Object) { ...@@ -175,8 +158,8 @@ Reject(Object) {
let index: Smi = 1; let index: Smi = 1;
try { try {
const fastIteratorResultMap = *NativeContextSlot( const fastIteratorResultMap = UnsafeCast<Map>(
nativeContext, ContextSlot::ITERATOR_RESULT_MAP_INDEX); nativeContext.elements[NativeContextSlot::ITERATOR_RESULT_MAP_INDEX]);
// 8. Repeat, // 8. Repeat,
while (true) { while (true) {
let nextValue: JSAny; let nextValue: JSAny;
...@@ -248,14 +231,12 @@ Reject(Object) { ...@@ -248,14 +231,12 @@ Reject(Object) {
rejectElementContext, index, nativeContext); rejectElementContext, index, nativeContext);
// q. Set remainingElementsCount.[[Value]] to // q. Set remainingElementsCount.[[Value]] to
// remainingElementsCount.[[Value]] + 1. // remainingElementsCount.[[Value]] + 1.
const remainingElementsCount = *ContextSlot( const remainingElementsCount = UnsafeCast<Smi>(
rejectElementContext, rejectElementContext
PromiseAnyRejectElementContextSlots:: .elements[PromiseAnyRejectElementContextSlots::
kPromiseAnyRejectElementRemainingSlot); kPromiseAnyRejectElementRemainingSlot]);
*ContextSlot( rejectElementContext.elements[PromiseAnyRejectElementContextSlots::
rejectElementContext, kPromiseAnyRejectElementRemainingSlot] =
PromiseAnyRejectElementContextSlots::
kPromiseAnyRejectElementRemainingSlot) =
remainingElementsCount + 1; remainingElementsCount + 1;
// r. Perform ? Invoke(nextPromise, "then", « // r. Perform ? Invoke(nextPromise, "then", «
...@@ -289,10 +270,13 @@ Reject(Object) { ...@@ -289,10 +270,13 @@ Reject(Object) {
// i. Set iteratorRecord.[[Done]] to true. // i. Set iteratorRecord.[[Done]] to true.
// ii. Set remainingElementsCount.[[Value]] to // ii. Set remainingElementsCount.[[Value]] to
// remainingElementsCount.[[Value]] - 1. // remainingElementsCount.[[Value]] - 1.
const remainingElementsCount = -- *ContextSlot( let remainingElementsCount = UnsafeCast<Smi>(
rejectElementContext, rejectElementContext.elements[PromiseAnyRejectElementContextSlots::
PromiseAnyRejectElementContextSlots:: kPromiseAnyRejectElementRemainingSlot]);
kPromiseAnyRejectElementRemainingSlot); remainingElementsCount -= 1;
rejectElementContext.elements[PromiseAnyRejectElementContextSlots::
kPromiseAnyRejectElementRemainingSlot] =
remainingElementsCount;
// iii. If remainingElementsCount.[[Value]] is 0, then // iii. If remainingElementsCount.[[Value]] is 0, then
if (remainingElementsCount == 0) deferred { if (remainingElementsCount == 0) deferred {
...@@ -301,10 +285,10 @@ Reject(Object) { ...@@ -301,10 +285,10 @@ Reject(Object) {
// We may already have elements in "errors" - this happens when the // We may already have elements in "errors" - this happens when the
// Thenable calls the reject callback immediately. // Thenable calls the reject callback immediately.
const errors: FixedArray = *ContextSlot( const errors = UnsafeCast<FixedArray>(
rejectElementContext, rejectElementContext
PromiseAnyRejectElementContextSlots:: .elements[PromiseAnyRejectElementContextSlots::
kPromiseAnyRejectElementErrorsSlot); kPromiseAnyRejectElementErrorsSlot]);
const error = ConstructAggregateError(errors); const error = ConstructAggregateError(errors);
// 3. Return ThrowCompletion(error). // 3. Return ThrowCompletion(error).
......
...@@ -57,7 +57,8 @@ PromiseConstructor( ...@@ -57,7 +57,8 @@ PromiseConstructor(
ThrowTypeError(MessageTemplate::kResolverNotAFunction, executor); ThrowTypeError(MessageTemplate::kResolverNotAFunction, executor);
} }
const promiseFun = *NativeContextSlot(ContextSlot::PROMISE_FUNCTION_INDEX); const promiseFun = UnsafeCast<JSFunction>(
context.elements[NativeContextSlot::PROMISE_FUNCTION_INDEX]);
// Silently fail if the stack looks fishy. // Silently fail if the stack looks fishy.
if (HasAccessCheckFailed(context, promiseFun, executor)) { if (HasAccessCheckFailed(context, promiseFun, executor)) {
......
...@@ -7,48 +7,41 @@ ...@@ -7,48 +7,41 @@
namespace promise { namespace promise {
type PromiseValueThunkOrReasonContext extends FunctionContext; // TODO(joshualitt): The below ContextSlots are only available on synthetic
extern enum PromiseValueThunkOrReasonContextSlot extends intptr // contexts created by the promise pipeline for use in the promise pipeline.
constexpr 'PromiseBuiltins::PromiseValueThunkOrReasonContextSlot' { // However, with Torque we should type the context and its slots to prevent
kValueSlot: Slot<PromiseValueThunkOrReasonContext, JSAny>, // accidentially using these slots on contexts which don't support them.
kPromiseValueThunkOrReasonContextLength const kPromiseBuiltinsValueSlot: constexpr ContextSlot
} generates 'PromiseBuiltins::kValueSlot';
const kPromiseBuiltinsOnFinallySlot: constexpr ContextSlot
type PromiseFinallyContext extends FunctionContext; generates 'PromiseBuiltins::kOnFinallySlot';
extern enum PromiseFinallyContextSlot extends intptr const kPromiseBuiltinsConstructorSlot: constexpr ContextSlot
constexpr 'PromiseBuiltins::PromiseFinallyContextSlot' { generates 'PromiseBuiltins::kConstructorSlot';
kOnFinallySlot: Slot<PromiseFinallyContext, Callable>, const kPromiseBuiltinsPromiseValueThunkOrReasonContextLength: constexpr int31
kConstructorSlot: Slot<PromiseFinallyContext, Constructor>, generates 'PromiseBuiltins::kPromiseValueThunkOrReasonContextLength';
kPromiseFinallyContextLength const kPromiseBuiltinsPromiseFinallyContextLength: constexpr int31
} generates 'PromiseBuiltins::kPromiseFinallyContextLength';
transitioning javascript builtin transitioning javascript builtin
PromiseValueThunkFinally( PromiseValueThunkFinally(
js-implicit context: Context, receiver: JSAny)(): JSAny { js-implicit context: Context, receiver: JSAny)(): JSAny {
const context = %RawDownCast<PromiseValueThunkOrReasonContext>(context); return UnsafeCast<JSAny>(context.elements[kPromiseBuiltinsValueSlot]);
return *ContextSlot(
context, PromiseValueThunkOrReasonContextSlot::kValueSlot);
} }
transitioning javascript builtin transitioning javascript builtin
PromiseThrowerFinally(js-implicit context: Context, receiver: JSAny)(): never { PromiseThrowerFinally(js-implicit context: Context, receiver: JSAny)(): never {
const context = %RawDownCast<PromiseValueThunkOrReasonContext>(context); const reason = UnsafeCast<JSAny>(context.elements[kPromiseBuiltinsValueSlot]);
const reason =
*ContextSlot(context, PromiseValueThunkOrReasonContextSlot::kValueSlot);
Throw(reason); Throw(reason);
} }
macro CreateThrowerFunction(implicit context: Context)( macro CreateThrowerFunction(implicit context: Context)(
nativeContext: NativeContext, reason: JSAny): JSFunction { nativeContext: NativeContext, reason: JSAny): JSFunction {
const throwerContext = %RawDownCast<PromiseValueThunkOrReasonContext>( const throwerContext = AllocateSyntheticFunctionContext(
AllocateSyntheticFunctionContext( nativeContext, kPromiseBuiltinsPromiseValueThunkOrReasonContextLength);
nativeContext, throwerContext.elements[kPromiseBuiltinsValueSlot] = reason;
PromiseValueThunkOrReasonContextSlot:: const map = UnsafeCast<Map>(
kPromiseValueThunkOrReasonContextLength)); nativeContext.elements
InitContextSlot( [NativeContextSlot::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX]);
throwerContext, PromiseValueThunkOrReasonContextSlot::kValueSlot, reason);
const map = *ContextSlot(
nativeContext, ContextSlot::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
const throwerInfo = PromiseThrowerFinallySharedFunConstant(); const throwerInfo = PromiseThrowerFinallySharedFunConstant();
return AllocateFunctionWithMapAndContext(map, throwerInfo, throwerContext); return AllocateFunctionWithMapAndContext(map, throwerInfo, throwerContext);
} }
...@@ -56,18 +49,17 @@ macro CreateThrowerFunction(implicit context: Context)( ...@@ -56,18 +49,17 @@ macro CreateThrowerFunction(implicit context: Context)(
transitioning javascript builtin transitioning javascript builtin
PromiseCatchFinally( PromiseCatchFinally(
js-implicit context: Context, receiver: JSAny)(reason: JSAny): JSAny { js-implicit context: Context, receiver: JSAny)(reason: JSAny): JSAny {
const context = %RawDownCast<PromiseFinallyContext>(context);
// 1. Let onFinally be F.[[OnFinally]]. // 1. Let onFinally be F.[[OnFinally]].
// 2. Assert: IsCallable(onFinally) is true. // 2. Assert: IsCallable(onFinally) is true.
const onFinally: Callable = const onFinally =
*ContextSlot(context, PromiseFinallyContextSlot::kOnFinallySlot); UnsafeCast<Callable>(context.elements[kPromiseBuiltinsOnFinallySlot]);
// 3. Let result be ? Call(onFinally). // 3. Let result be ? Call(onFinally).
const result = Call(context, onFinally, Undefined); const result = Call(context, onFinally, Undefined);
// 4. Let C be F.[[Constructor]]. // 4. Let C be F.[[Constructor]].
const constructor: Constructor = const constructor =
*ContextSlot(context, PromiseFinallyContextSlot::kConstructorSlot); UnsafeCast<JSFunction>(context.elements[kPromiseBuiltinsConstructorSlot]);
// 5. Assert: IsConstructor(C) is true. // 5. Assert: IsConstructor(C) is true.
assert(IsConstructor(constructor)); assert(IsConstructor(constructor));
...@@ -85,16 +77,12 @@ PromiseCatchFinally( ...@@ -85,16 +77,12 @@ PromiseCatchFinally(
macro CreateValueThunkFunction(implicit context: Context)( macro CreateValueThunkFunction(implicit context: Context)(
nativeContext: NativeContext, value: JSAny): JSFunction { nativeContext: NativeContext, value: JSAny): JSFunction {
const valueThunkContext = %RawDownCast<PromiseValueThunkOrReasonContext>( const valueThunkContext = AllocateSyntheticFunctionContext(
AllocateSyntheticFunctionContext( nativeContext, kPromiseBuiltinsPromiseValueThunkOrReasonContextLength);
nativeContext, valueThunkContext.elements[kPromiseBuiltinsValueSlot] = value;
PromiseValueThunkOrReasonContextSlot:: const map = UnsafeCast<Map>(
kPromiseValueThunkOrReasonContextLength)); nativeContext.elements
InitContextSlot( [NativeContextSlot::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX]);
valueThunkContext, PromiseValueThunkOrReasonContextSlot::kValueSlot,
value);
const map = *ContextSlot(
nativeContext, ContextSlot::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
const valueThunkInfo = PromiseValueThunkFinallySharedFunConstant(); const valueThunkInfo = PromiseValueThunkFinallySharedFunConstant();
return AllocateFunctionWithMapAndContext( return AllocateFunctionWithMapAndContext(
map, valueThunkInfo, valueThunkContext); map, valueThunkInfo, valueThunkContext);
...@@ -103,18 +91,17 @@ macro CreateValueThunkFunction(implicit context: Context)( ...@@ -103,18 +91,17 @@ macro CreateValueThunkFunction(implicit context: Context)(
transitioning javascript builtin transitioning javascript builtin
PromiseThenFinally( PromiseThenFinally(
js-implicit context: Context, receiver: JSAny)(value: JSAny): JSAny { js-implicit context: Context, receiver: JSAny)(value: JSAny): JSAny {
const context = %RawDownCast<PromiseFinallyContext>(context);
// 1. Let onFinally be F.[[OnFinally]]. // 1. Let onFinally be F.[[OnFinally]].
// 2. Assert: IsCallable(onFinally) is true. // 2. Assert: IsCallable(onFinally) is true.
const onFinally = const onFinally =
*ContextSlot(context, PromiseFinallyContextSlot::kOnFinallySlot); UnsafeCast<Callable>(context.elements[kPromiseBuiltinsOnFinallySlot]);
// 3. Let result be ? Call(onFinally). // 3. Let result be ? Call(onFinally).
const result = Call(context, onFinally, Undefined); const result = Call(context, onFinally, Undefined);
// 4. Let C be F.[[Constructor]]. // 4. Let C be F.[[Constructor]].
const constructor = const constructor =
*ContextSlot(context, PromiseFinallyContextSlot::kConstructorSlot); UnsafeCast<JSFunction>(context.elements[kPromiseBuiltinsConstructorSlot]);
// 5. Assert: IsConstructor(C) is true. // 5. Assert: IsConstructor(C) is true.
assert(IsConstructor(constructor)); assert(IsConstructor(constructor));
...@@ -137,17 +124,14 @@ struct PromiseFinallyFunctions { ...@@ -137,17 +124,14 @@ struct PromiseFinallyFunctions {
macro CreatePromiseFinallyFunctions(implicit context: Context)( macro CreatePromiseFinallyFunctions(implicit context: Context)(
nativeContext: NativeContext, onFinally: Callable, nativeContext: NativeContext, onFinally: Callable,
constructor: Constructor): PromiseFinallyFunctions { constructor: JSReceiver): PromiseFinallyFunctions {
const promiseContext = const promiseContext = AllocateSyntheticFunctionContext(
%RawDownCast<PromiseFinallyContext>(AllocateSyntheticFunctionContext( nativeContext, kPromiseBuiltinsPromiseFinallyContextLength);
nativeContext, promiseContext.elements[kPromiseBuiltinsOnFinallySlot] = onFinally;
PromiseFinallyContextSlot::kPromiseFinallyContextLength)); promiseContext.elements[kPromiseBuiltinsConstructorSlot] = constructor;
InitContextSlot( const map = UnsafeCast<Map>(
promiseContext, PromiseFinallyContextSlot::kOnFinallySlot, onFinally); nativeContext.elements
InitContextSlot( [NativeContextSlot::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX]);
promiseContext, PromiseFinallyContextSlot::kConstructorSlot, constructor);
const map = *ContextSlot(
nativeContext, ContextSlot::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
const thenFinallyInfo = PromiseThenFinallySharedFunConstant(); const thenFinallyInfo = PromiseThenFinallySharedFunConstant();
const thenFinally = const thenFinally =
AllocateFunctionWithMapAndContext(map, thenFinallyInfo, promiseContext); AllocateFunctionWithMapAndContext(map, thenFinallyInfo, promiseContext);
...@@ -170,15 +154,15 @@ PromisePrototypeFinally( ...@@ -170,15 +154,15 @@ PromisePrototypeFinally(
// 3. Let C be ? SpeciesConstructor(promise, %Promise%). // 3. Let C be ? SpeciesConstructor(promise, %Promise%).
const nativeContext = LoadNativeContext(context); const nativeContext = LoadNativeContext(context);
const promiseFun = *NativeContextSlot(ContextSlot::PROMISE_FUNCTION_INDEX); const promiseFun = UnsafeCast<Callable>(
nativeContext.elements[NativeContextSlot::PROMISE_FUNCTION_INDEX]);
let constructor: Constructor = UnsafeCast<Constructor>(promiseFun); let constructor: JSReceiver = promiseFun;
const receiverMap = jsReceiver.map; const receiverMap = jsReceiver.map;
if (!IsJSPromiseMap(receiverMap) || if (!IsJSPromiseMap(receiverMap) ||
!IsPromiseSpeciesLookupChainIntact(nativeContext, receiverMap)) !IsPromiseSpeciesLookupChainIntact(nativeContext, receiverMap))
deferred { deferred {
constructor = constructor = SpeciesConstructor(jsReceiver, promiseFun);
UnsafeCast<Constructor>(SpeciesConstructor(jsReceiver, promiseFun));
} }
// 4. Assert: IsConstructor(C) is true. // 4. Assert: IsConstructor(C) is true.
......
...@@ -22,7 +22,8 @@ PromiseResolveThenableJob(implicit context: Context)( ...@@ -22,7 +22,8 @@ PromiseResolveThenableJob(implicit context: Context)(
// We take the generic (slow-)path if a PromiseHook is enabled or the // We take the generic (slow-)path if a PromiseHook is enabled or the
// debugger is active, to make sure we expose spec compliant behavior. // debugger is active, to make sure we expose spec compliant behavior.
const nativeContext = LoadNativeContext(context); const nativeContext = LoadNativeContext(context);
const promiseThen = *NativeContextSlot(ContextSlot::PROMISE_THEN_INDEX); const promiseThen =
nativeContext.elements[NativeContextSlot::PROMISE_THEN_INDEX];
const thenableMap = thenable.map; const thenableMap = thenable.map;
if (TaggedEqual(then, promiseThen) && IsJSPromiseMap(thenableMap) && if (TaggedEqual(then, promiseThen) && IsJSPromiseMap(thenableMap) &&
!IsPromiseHookEnabledOrDebugIsActiveOrHasAsyncEventDelegate() && !IsPromiseHookEnabledOrDebugIsActiveOrHasAsyncEventDelegate() &&
......
...@@ -38,7 +38,9 @@ macro PromiseInit(promise: JSPromise): void { ...@@ -38,7 +38,9 @@ macro PromiseInit(promise: JSPromise): void {
} }
macro InnerNewJSPromise(implicit context: Context)(): JSPromise { macro InnerNewJSPromise(implicit context: Context)(): JSPromise {
const promiseFun = *NativeContextSlot(ContextSlot::PROMISE_FUNCTION_INDEX); const nativeContext = LoadNativeContext(context);
const promiseFun = UnsafeCast<JSFunction>(
nativeContext.elements[NativeContextSlot::PROMISE_FUNCTION_INDEX]);
assert(IsFunctionWithPrototypeSlotMap(promiseFun.map)); assert(IsFunctionWithPrototypeSlotMap(promiseFun.map));
const promiseMap = UnsafeCast<Map>(promiseFun.prototype_or_initial_map); const promiseMap = UnsafeCast<Map>(promiseFun.prototype_or_initial_map);
const promiseHeapObject = promise_internal::AllocateJSPromise(context); const promiseHeapObject = promise_internal::AllocateJSPromise(context);
...@@ -68,8 +70,8 @@ macro NewPromiseFulfillReactionJobTask(implicit context: Context)( ...@@ -68,8 +70,8 @@ macro NewPromiseFulfillReactionJobTask(implicit context: Context)(
handler, handler,
promise_or_capability: promiseOrCapability, promise_or_capability: promiseOrCapability,
continuation_preserved_embedder_data: continuation_preserved_embedder_data:
*ContextSlot( nativeContext.elements
nativeContext, ContextSlot::CONTINUATION_PRESERVED_EMBEDDER_DATA_INDEX) [NativeContextSlot::CONTINUATION_PRESERVED_EMBEDDER_DATA_INDEX]
}; };
} }
...@@ -85,8 +87,8 @@ macro NewPromiseRejectReactionJobTask(implicit context: Context)( ...@@ -85,8 +87,8 @@ macro NewPromiseRejectReactionJobTask(implicit context: Context)(
handler, handler,
promise_or_capability: promiseOrCapability, promise_or_capability: promiseOrCapability,
continuation_preserved_embedder_data: continuation_preserved_embedder_data:
*ContextSlot( nativeContext.elements
nativeContext, ContextSlot::CONTINUATION_PRESERVED_EMBEDDER_DATA_INDEX) [NativeContextSlot::CONTINUATION_PRESERVED_EMBEDDER_DATA_INDEX]
}; };
} }
...@@ -144,8 +146,8 @@ macro NewPromiseReaction(implicit context: Context)( ...@@ -144,8 +146,8 @@ macro NewPromiseReaction(implicit context: Context)(
fulfill_handler: fulfillHandler, fulfill_handler: fulfillHandler,
promise_or_capability: promiseOrCapability, promise_or_capability: promiseOrCapability,
continuation_preserved_embedder_data: continuation_preserved_embedder_data:
*ContextSlot( nativeContext.elements
nativeContext, ContextSlot::CONTINUATION_PRESERVED_EMBEDDER_DATA_INDEX) [NativeContextSlot::CONTINUATION_PRESERVED_EMBEDDER_DATA_INDEX]
}; };
} }
...@@ -208,8 +210,8 @@ macro InvokeThen<F: type>(implicit context: Context)( ...@@ -208,8 +210,8 @@ macro InvokeThen<F: type>(implicit context: Context)(
if (!Is<Smi>(receiver) && if (!Is<Smi>(receiver) &&
IsPromiseThenLookupChainIntact( IsPromiseThenLookupChainIntact(
nativeContext, UnsafeCast<HeapObject>(receiver).map)) { nativeContext, UnsafeCast<HeapObject>(receiver).map)) {
const then = const then = UnsafeCast<JSAny>(
*NativeContextSlot(nativeContext, ContextSlot::PROMISE_THEN_INDEX); nativeContext.elements[NativeContextSlot::PROMISE_THEN_INDEX]);
return callFunctor.Call(nativeContext, then, receiver, arg1, arg2); return callFunctor.Call(nativeContext, then, receiver, arg1, arg2);
} else } else
deferred { deferred {
......
...@@ -50,8 +50,8 @@ PromiseRace( ...@@ -50,8 +50,8 @@ PromiseRace(
// Let result be PerformPromiseRace(iteratorRecord, C, promiseCapability). // Let result be PerformPromiseRace(iteratorRecord, C, promiseCapability).
try { try {
const fastIteratorResultMap = *NativeContextSlot( const fastIteratorResultMap = UnsafeCast<Map>(
nativeContext, ContextSlot::ITERATOR_RESULT_MAP_INDEX); nativeContext.elements[NativeContextSlot::ITERATOR_RESULT_MAP_INDEX]);
while (true) { while (true) {
let nextValue: JSAny; let nextValue: JSAny;
try { try {
......
...@@ -30,7 +30,8 @@ transitioning builtin ...@@ -30,7 +30,8 @@ transitioning builtin
PromiseResolve(implicit context: Context)( PromiseResolve(implicit context: Context)(
constructor: JSReceiver, value: JSAny): JSAny { constructor: JSReceiver, value: JSAny): JSAny {
const nativeContext = LoadNativeContext(context); const nativeContext = LoadNativeContext(context);
const promiseFun = *NativeContextSlot(ContextSlot::PROMISE_FUNCTION_INDEX); const promiseFun =
nativeContext.elements[NativeContextSlot::PROMISE_FUNCTION_INDEX];
try { try {
// Check if {value} is a JSPromise. // Check if {value} is a JSPromise.
const value = Cast<JSPromise>(value) otherwise NeedToAllocate; const value = Cast<JSPromise>(value) otherwise NeedToAllocate;
...@@ -40,9 +41,7 @@ PromiseResolve(implicit context: Context)( ...@@ -40,9 +41,7 @@ PromiseResolve(implicit context: Context)(
// intact, as that guards the lookup path for "constructor" on // intact, as that guards the lookup path for "constructor" on
// JSPromise instances which have the (initial) Promise.prototype. // JSPromise instances which have the (initial) Promise.prototype.
const promisePrototype = const promisePrototype =
*NativeContextSlot(ContextSlot::PROMISE_PROTOTYPE_INDEX); nativeContext.elements[NativeContextSlot::PROMISE_PROTOTYPE_INDEX];
// Check that Torque load elimination works.
static_assert(nativeContext == LoadNativeContext(context));
if (value.map.prototype != promisePrototype) { if (value.map.prototype != promisePrototype) {
goto SlowConstructor; goto SlowConstructor;
} }
...@@ -139,7 +138,8 @@ ResolvePromise(implicit context: Context)( ...@@ -139,7 +138,8 @@ ResolvePromise(implicit context: Context)(
assert(IsJSReceiverMap(resolutionMap)); assert(IsJSReceiverMap(resolutionMap));
assert(!IsPromiseThenProtectorCellInvalid()); assert(!IsPromiseThenProtectorCellInvalid());
if (resolutionMap == if (resolutionMap ==
*NativeContextSlot(ContextSlot::ITERATOR_RESULT_MAP_INDEX)) { nativeContext
.elements[NativeContextSlot::ITERATOR_RESULT_MAP_INDEX]) {
return FulfillPromise(promise, resolution); return FulfillPromise(promise, resolution);
} else { } else {
goto Slow; goto Slow;
...@@ -147,12 +147,10 @@ ResolvePromise(implicit context: Context)( ...@@ -147,12 +147,10 @@ ResolvePromise(implicit context: Context)(
} }
const promisePrototype = const promisePrototype =
*NativeContextSlot(ContextSlot::PROMISE_PROTOTYPE_INDEX); nativeContext.elements[NativeContextSlot::PROMISE_PROTOTYPE_INDEX];
if (resolutionMap.prototype == promisePrototype) { if (resolutionMap.prototype == promisePrototype) {
// The {resolution} is a native Promise in this case. // The {resolution} is a native Promise in this case.
then = *NativeContextSlot(ContextSlot::PROMISE_THEN_INDEX); then = nativeContext.elements[NativeContextSlot::PROMISE_THEN_INDEX];
// Check that Torque load elimination works.
static_assert(nativeContext == LoadNativeContext(context));
goto Enqueue; goto Enqueue;
} }
goto Slow; goto Slow;
......
...@@ -10,7 +10,7 @@ macro ...@@ -10,7 +10,7 @@ macro
IsPromiseSpeciesLookupChainIntact( IsPromiseSpeciesLookupChainIntact(
nativeContext: NativeContext, promiseMap: Map): bool { nativeContext: NativeContext, promiseMap: Map): bool {
const promisePrototype = const promisePrototype =
*NativeContextSlot(nativeContext, ContextSlot::PROMISE_PROTOTYPE_INDEX); nativeContext.elements[NativeContextSlot::PROMISE_PROTOTYPE_INDEX];
if (IsForceSlowPath()) return false; if (IsForceSlowPath()) return false;
if (promiseMap.prototype != promisePrototype) return false; if (promiseMap.prototype != promisePrototype) return false;
return !IsPromiseSpeciesProtectorCellInvalid(); return !IsPromiseSpeciesProtectorCellInvalid();
...@@ -27,7 +27,8 @@ PromisePrototypeThen(js-implicit context: NativeContext, receiver: JSAny)( ...@@ -27,7 +27,8 @@ PromisePrototypeThen(js-implicit context: NativeContext, receiver: JSAny)(
receiver); receiver);
// 3. Let C be ? SpeciesConstructor(promise, %Promise%). // 3. Let C be ? SpeciesConstructor(promise, %Promise%).
const promiseFun = *NativeContextSlot(ContextSlot::PROMISE_FUNCTION_INDEX); const promiseFun = UnsafeCast<JSFunction>(
context.elements[NativeContextSlot::PROMISE_FUNCTION_INDEX]);
// 4. Let resultCapability be ? NewPromiseCapability(C). // 4. Let resultCapability be ? NewPromiseCapability(C).
let resultPromiseOrCapability: JSPromise|PromiseCapability; let resultPromiseOrCapability: JSPromise|PromiseCapability;
......
...@@ -9,24 +9,20 @@ namespace proxy { ...@@ -9,24 +9,20 @@ namespace proxy {
// Proxy Revocation Functions // Proxy Revocation Functions
// https://tc39.github.io/ecma262/#sec-proxy-revocation-functions // https://tc39.github.io/ecma262/#sec-proxy-revocation-functions
transitioning javascript builtin transitioning javascript builtin
ProxyRevoke(js-implicit context: Context)(): Undefined { ProxyRevoke(js-implicit context: NativeContext)(): Undefined {
const context = %RawDownCast<ProxyRevokeFunctionContext>(context);
// 1. Let p be F.[[RevocableProxy]]. // 1. Let p be F.[[RevocableProxy]].
const proxySlot:&(JSProxy | Null) = const proxyObject: Object = context.elements[PROXY_SLOT];
ContextSlot(context, ProxyRevokeFunctionContextSlot::kProxySlot);
typeswitch (*proxySlot) {
case (Null): {
// 2. If p is null, return undefined // 2. If p is null, return undefined
if (proxyObject == Null) {
return Undefined; return Undefined;
} }
case (proxy: JSProxy): {
// 3. Set F.[[RevocableProxy]] to null. // 3. Set F.[[RevocableProxy]] to null.
*proxySlot = Null; context.elements[PROXY_SLOT] = Null;
// 4. Assert: p is a Proxy object. // 4. Assert: p is a Proxy object.
assert(Is<JSProxy>(proxy)); const proxy: JSProxy = UnsafeCast<JSProxy>(proxyObject);
// 5. Set p.[[ProxyTarget]] to null. // 5. Set p.[[ProxyTarget]] to null.
proxy.target = Null; proxy.target = Null;
...@@ -36,7 +32,5 @@ ProxyRevoke(js-implicit context: Context)(): Undefined { ...@@ -36,7 +32,5 @@ ProxyRevoke(js-implicit context: Context)(): Undefined {
// 7. Return undefined. // 7. Return undefined.
return Undefined; return Undefined;
}
}
} }
} }
...@@ -23,11 +23,4 @@ const kProxyGet: constexpr int31 ...@@ -23,11 +23,4 @@ const kProxyGet: constexpr int31
generates 'JSProxy::AccessKind::kGet'; generates 'JSProxy::AccessKind::kGet';
const kProxySet: constexpr int31 const kProxySet: constexpr int31
generates 'JSProxy::AccessKind::kSet'; generates 'JSProxy::AccessKind::kSet';
type ProxyRevokeFunctionContext extends FunctionContext;
extern enum ProxyRevokeFunctionContextSlot extends intptr
constexpr 'ProxiesCodeStubAssembler::ProxyRevokeFunctionContextSlot' {
kProxySlot: Slot<ProxyRevokeFunctionContext, JSProxy|Null>,
kProxyContextLength
}
} }
...@@ -155,8 +155,10 @@ transitioning macro RegExpPrototypeExecBody(implicit context: Context)( ...@@ -155,8 +155,10 @@ transitioning macro RegExpPrototypeExecBody(implicit context: Context)(
regexp, matchIndices, string, lastIndex); regexp, matchIndices, string, lastIndex);
} }
macro LoadRegExpFunction(nativeContext: NativeContext): JSFunction { macro LoadRegExpFunction(implicit context: Context)(
return *NativeContextSlot(nativeContext, ContextSlot::REGEXP_FUNCTION_INDEX); nativeContext: NativeContext): JSFunction {
return UnsafeCast<JSFunction>(
nativeContext.elements[NativeContextSlot::REGEXP_FUNCTION_INDEX]);
} }
// Note this doesn't guarantee const-ness of object properties, just // Note this doesn't guarantee const-ness of object properties, just
......
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_BUILTINS_TORQUE_CSA_HEADER_INCLUDES_H_
#define V8_BUILTINS_TORQUE_CSA_HEADER_INCLUDES_H_
// This file is included by Torque-generated CSA headers and contains
// includes necessary for these headers.
#include "src/builtins/builtins-promise.h"
#include "src/builtins/builtins-proxy-gen.h"
#include "src/codegen/code-stub-assembler.h"
#include "src/compiler/code-assembler.h"
#include "src/utils/utils.h"
#include "torque-generated/csa-types-tq.h"
#include "torque-generated/field-offsets-tq.h"
#endif // V8_BUILTINS_TORQUE_CSA_HEADER_INCLUDES_H_
...@@ -25,11 +25,6 @@ macro NewReference<T: type>(object: HeapObject, offset: intptr):&T { ...@@ -25,11 +25,6 @@ macro NewReference<T: type>(object: HeapObject, offset: intptr):&T {
return %RawDownCast<&T>( return %RawDownCast<&T>(
Reference<T>{object: object, offset: offset, unsafeMarker: Unsafe {}}); Reference<T>{object: object, offset: offset, unsafeMarker: Unsafe {}});
} }
macro ReferenceCast<T: type, U: type>(ref:&U):&T {
const ref = NewReference<T>(ref.object, ref.offset);
UnsafeCast<T>(*ref);
return ref;
}
} // namespace unsafe } // namespace unsafe
struct Slice<T: type> { struct Slice<T: type> {
......
...@@ -13037,6 +13037,34 @@ void CodeStubAssembler::PerformStackCheck(TNode<Context> context) { ...@@ -13037,6 +13037,34 @@ void CodeStubAssembler::PerformStackCheck(TNode<Context> context) {
BIND(&ok); BIND(&ok);
} }
TNode<Context> CodeStubAssembler::AllocateSyntheticFunctionContext(
TNode<NativeContext> native_context, int slots) {
DCHECK_GE(slots, Context::MIN_CONTEXT_SLOTS);
TNode<HeapObject> context_heap_object =
AllocateInNewSpace(FixedArray::SizeFor(slots));
InitializeSyntheticFunctionContext(native_context, context_heap_object,
slots);
return CAST(context_heap_object);
}
void CodeStubAssembler::InitializeSyntheticFunctionContext(
TNode<NativeContext> native_context, TNode<HeapObject> context_heap_object,
int slots) {
DCHECK_GE(slots, Context::MIN_CONTEXT_SLOTS);
TNode<Map> map = CAST(
LoadContextElement(native_context, Context::FUNCTION_CONTEXT_MAP_INDEX));
StoreMapNoWriteBarrier(context_heap_object, map);
StoreObjectFieldNoWriteBarrier(context_heap_object, FixedArray::kLengthOffset,
SmiConstant(slots));
TNode<Context> context = CAST(context_heap_object);
const TNode<Object> empty_scope_info = LoadRoot(RootIndex::kEmptyScopeInfo);
StoreContextElementNoWriteBarrier(context, Context::SCOPE_INFO_INDEX,
empty_scope_info);
StoreContextElementNoWriteBarrier(context, Context::PREVIOUS_INDEX,
UndefinedConstant());
}
TNode<Object> CodeStubAssembler::CallApiCallback( TNode<Object> CodeStubAssembler::CallApiCallback(
TNode<Object> context, TNode<RawPtrT> callback, TNode<IntPtrT> argc, TNode<Object> context, TNode<RawPtrT> callback, TNode<IntPtrT> argc,
TNode<Object> data, TNode<Object> holder, TNode<Object> receiver) { TNode<Object> data, TNode<Object> holder, TNode<Object> receiver) {
......
...@@ -128,7 +128,6 @@ enum class PrimitiveType { kBoolean, kNumber, kString, kSymbol }; ...@@ -128,7 +128,6 @@ enum class PrimitiveType { kBoolean, kNumber, kString, kSymbol };
V(default_string, default_string, DefaultString) \ V(default_string, default_string, DefaultString) \
V(EmptyByteArray, empty_byte_array, EmptyByteArray) \ V(EmptyByteArray, empty_byte_array, EmptyByteArray) \
V(EmptyFixedArray, empty_fixed_array, EmptyFixedArray) \ V(EmptyFixedArray, empty_fixed_array, EmptyFixedArray) \
V(EmptyScopeInfo, empty_scope_info, EmptyScopeInfo) \
V(EmptyPropertyDictionary, empty_property_dictionary, \ V(EmptyPropertyDictionary, empty_property_dictionary, \
EmptyPropertyDictionary) \ EmptyPropertyDictionary) \
V(EmptySlowElementDictionary, empty_slow_element_dictionary, \ V(EmptySlowElementDictionary, empty_slow_element_dictionary, \
...@@ -3709,6 +3708,12 @@ class V8_EXPORT_PRIVATE CodeStubAssembler ...@@ -3709,6 +3708,12 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
TNode<IntPtrT> TryToIntptr(SloppyTNode<Object> key, Label* if_not_intptr, TNode<IntPtrT> TryToIntptr(SloppyTNode<Object> key, Label* if_not_intptr,
TVariable<Int32T>* var_instance_type = nullptr); TVariable<Int32T>* var_instance_type = nullptr);
TNode<Context> AllocateSyntheticFunctionContext(
TNode<NativeContext> native_context, int slots);
void InitializeSyntheticFunctionContext(TNode<NativeContext> native_context,
TNode<HeapObject> context_heap_object,
int slots);
TNode<JSArray> ArrayCreate(TNode<Context> context, TNode<Number> length); TNode<JSArray> ArrayCreate(TNode<Context> context, TNode<Number> length);
// Allocate a clone of a mutable primitive, if {object} is a mutable // Allocate a clone of a mutable primitive, if {object} is a mutable
......
...@@ -150,7 +150,7 @@ macro NewParameterMapIterator( ...@@ -150,7 +150,7 @@ macro NewParameterMapIterator(
context: Context, formalParameterCount: intptr, context: Context, formalParameterCount: intptr,
mappedCount: intptr): ParameterMapIterator { mappedCount: intptr): ParameterMapIterator {
const flags = context.GetScopeInfo().flags; const flags = context.GetScopeInfo().flags;
let contextHeaderSize: intptr = ContextSlot::MIN_CONTEXT_SLOTS; let contextHeaderSize: intptr = MIN_CONTEXT_SLOTS;
if (flags.has_context_extension_slot) ++contextHeaderSize; if (flags.has_context_extension_slot) ++contextHeaderSize;
// Copy the parameter slots and the holes in the arguments. // Copy the parameter slots and the holes in the arguments.
// We need to fill in mapped_count slots. They index the context, // We need to fill in mapped_count slots. They index the context,
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
@abstract @abstract
extern class Context extends HeapObject { extern class Context extends HeapObject {
macro GetScopeInfo(): ScopeInfo { macro GetScopeInfo(): ScopeInfo {
return *ContextSlot(this, ContextSlot::SCOPE_INFO_INDEX); return UnsafeCast<ScopeInfo>(this.elements[0]);
} }
const length: Smi; const length: Smi;
elements[length]: Object; elements[length]: Object;
...@@ -17,117 +17,57 @@ extern class CatchContext extends Context generates 'TNode<Context>'; ...@@ -17,117 +17,57 @@ extern class CatchContext extends Context generates 'TNode<Context>';
extern class DebugEvaluateContext extends Context extern class DebugEvaluateContext extends Context
generates 'TNode<Context>'; generates 'TNode<Context>';
extern class EvalContext extends Context generates 'TNode<Context>'; extern class EvalContext extends Context generates 'TNode<Context>';
extern class FunctionContext extends Context generates 'TNode<Context>';
extern class ModuleContext extends Context generates 'TNode<Context>'; extern class ModuleContext extends Context generates 'TNode<Context>';
extern class NativeContext extends Context;
extern class ScriptContext extends Context generates 'TNode<Context>'; extern class ScriptContext extends Context generates 'TNode<Context>';
extern class WithContext extends Context generates 'TNode<Context>'; extern class WithContext extends Context generates 'TNode<Context>';
extern class FunctionContext extends Context generates 'TNode<Context>'; const MIN_CONTEXT_SLOTS: constexpr int31
generates 'Context::MIN_CONTEXT_SLOTS';
const kInitialContextSlotValue: Smi = 0;
extern enum NativeContextSlot extends intptr constexpr 'Context::Field' {
@export AGGREGATE_ERROR_FUNCTION_INDEX,
macro AllocateSyntheticFunctionContext( ARRAY_BUFFER_FUN_INDEX,
nativeContext: NativeContext, slots: constexpr int31): FunctionContext { ARRAY_BUFFER_NOINIT_FUN_INDEX,
return AllocateSyntheticFunctionContext( ARRAY_BUFFER_MAP_INDEX,
nativeContext, Convert<intptr>(slots)); ARRAY_FUNCTION_INDEX,
} ARRAY_JOIN_STACK_INDEX,
OBJECT_FUNCTION_INDEX,
macro AllocateSyntheticFunctionContext( ITERATOR_RESULT_MAP_INDEX,
nativeContext: NativeContext, slots: intptr): FunctionContext { JS_ARRAY_PACKED_ELEMENTS_MAP_INDEX,
static_assert(slots >= ContextSlot::MIN_CONTEXT_SLOTS); JS_ARRAY_PACKED_SMI_ELEMENTS_MAP_INDEX,
const map = MATH_RANDOM_CACHE_INDEX,
*ContextSlot(nativeContext, ContextSlot::FUNCTION_CONTEXT_MAP_INDEX); MATH_RANDOM_INDEX_INDEX,
const result = new FunctionContext{ NUMBER_FUNCTION_INDEX,
map, PROXY_REVOCABLE_RESULT_MAP_INDEX,
length: Convert<Smi>(slots), REFLECT_APPLY_INDEX,
elements: ...ConstantIterator<Smi>(kInitialContextSlotValue) REGEXP_FUNCTION_INDEX,
}; REGEXP_LAST_MATCH_INFO_INDEX,
InitContextSlot(result, ContextSlot::SCOPE_INFO_INDEX, kEmptyScopeInfo); INITIAL_STRING_ITERATOR_MAP_INDEX,
InitContextSlot(result, ContextSlot::PREVIOUS_INDEX, Undefined); INITIAL_ARRAY_ITERATOR_MAP_INDEX,
return result; SLOW_OBJECT_WITH_NULL_PROTOTYPE_MAP,
} STRICT_ARGUMENTS_MAP_INDEX,
SLOPPY_ARGUMENTS_MAP_INDEX,
extern class NativeContext extends Context; FAST_ALIASED_ARGUMENTS_MAP_INDEX,
type Slot<Container : type extends Context, T : type extends Object> extends PROMISE_FUNCTION_INDEX,
intptr; PROMISE_THEN_INDEX,
PROMISE_PROTOTYPE_INDEX,
// We cannot use ContextSlot() for initialization since that one asserts the STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX,
// slot has the right type already.
macro InitContextSlot< CONTINUATION_PRESERVED_EMBEDDER_DATA_INDEX,
ArgumentContext: type, AnnotatedContext: type, T: type, U: type>(
context: ArgumentContext, index: Slot<AnnotatedContext, T>, value: U) { BOUND_FUNCTION_WITH_CONSTRUCTOR_MAP_INDEX,
// Make sure the arguments have the right type. BOUND_FUNCTION_WITHOUT_CONSTRUCTOR_MAP_INDEX,
const context: AnnotatedContext = context;
const value: T = value;
assert(TaggedEqual(context.elements[index], kInitialContextSlotValue));
context.elements[index] = value;
}
macro ContextSlot<ArgumentContext: type, AnnotatedContext: type, T: type>(
context: ArgumentContext, index: Slot<AnnotatedContext, T>):&T {
const context: AnnotatedContext = context;
return torque_internal::unsafe::ReferenceCast<T>(&context.elements[index]);
}
macro NativeContextSlot<T: type>(
context: NativeContext, index: Slot<NativeContext, T>):&T {
return ContextSlot(context, index);
}
macro NativeContextSlot<T: type>(
context: Context, index: Slot<NativeContext, T>):&T {
return ContextSlot(LoadNativeContext(context), index);
}
macro NativeContextSlot<C: type, T: type>(implicit context: C)(
index: Slot<NativeContext, T>):&T {
return NativeContextSlot(context, index);
}
extern enum ContextSlot extends intptr constexpr 'Context::Field' {
SCOPE_INFO_INDEX: Slot<Context, ScopeInfo>,
// Zero is used for the NativeContext, Undefined is used for synthetic
// function contexts.
PREVIOUS_INDEX: Slot<Context, Context|Zero|Undefined>,
AGGREGATE_ERROR_FUNCTION_INDEX: Slot<NativeContext, JSFunction>,
ARRAY_BUFFER_FUN_INDEX: Slot<NativeContext, Constructor>,
ARRAY_BUFFER_NOINIT_FUN_INDEX: Slot<NativeContext, JSFunction>,
ARRAY_BUFFER_MAP_INDEX: Slot<NativeContext, Map>,
ARRAY_FUNCTION_INDEX: Slot<NativeContext, JSFunction>,
ARRAY_JOIN_STACK_INDEX: Slot<NativeContext, Undefined|FixedArray>,
OBJECT_FUNCTION_INDEX: Slot<NativeContext, JSFunction>,
ITERATOR_RESULT_MAP_INDEX: Slot<NativeContext, Map>,
JS_ARRAY_PACKED_ELEMENTS_MAP_INDEX: Slot<NativeContext, Map>,
JS_ARRAY_PACKED_SMI_ELEMENTS_MAP_INDEX: Slot<NativeContext, Map>,
MATH_RANDOM_CACHE_INDEX: Slot<NativeContext, FixedDoubleArray>,
MATH_RANDOM_INDEX_INDEX: Slot<NativeContext, Smi>,
NUMBER_FUNCTION_INDEX: Slot<NativeContext, JSFunction>,
PROXY_REVOCABLE_RESULT_MAP_INDEX: Slot<NativeContext, Map>,
REFLECT_APPLY_INDEX: Slot<NativeContext, Callable>,
REGEXP_FUNCTION_INDEX: Slot<NativeContext, JSFunction>,
REGEXP_LAST_MATCH_INFO_INDEX: Slot<NativeContext, RegExpMatchInfo>,
INITIAL_STRING_ITERATOR_MAP_INDEX: Slot<NativeContext, Map>,
INITIAL_ARRAY_ITERATOR_MAP_INDEX: Slot<NativeContext, Map>,
SLOW_OBJECT_WITH_NULL_PROTOTYPE_MAP: Slot<NativeContext, Map>,
STRICT_ARGUMENTS_MAP_INDEX: Slot<NativeContext, Map>,
SLOPPY_ARGUMENTS_MAP_INDEX: Slot<NativeContext, Map>,
FAST_ALIASED_ARGUMENTS_MAP_INDEX: Slot<NativeContext, Map>,
FUNCTION_CONTEXT_MAP_INDEX: Slot<NativeContext, Map>,
PROMISE_FUNCTION_INDEX: Slot<NativeContext, JSFunction>,
PROMISE_THEN_INDEX: Slot<NativeContext, JSFunction>,
PROMISE_PROTOTYPE_INDEX: Slot<NativeContext, JSObject>,
STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX: Slot<NativeContext, Map>,
CONTINUATION_PRESERVED_EMBEDDER_DATA_INDEX: Slot<NativeContext, HeapObject>,
BOUND_FUNCTION_WITH_CONSTRUCTOR_MAP_INDEX: Slot<NativeContext, Map>,
BOUND_FUNCTION_WITHOUT_CONSTRUCTOR_MAP_INDEX: Slot<NativeContext, Map>,
MIN_CONTEXT_SLOTS,
... ...
} }
type ContextSlot extends intptr
generates 'TNode<IntPtrT>' constexpr 'int32_t';
const PROXY_SLOT: constexpr ContextSlot
generates 'Context::MIN_CONTEXT_SLOTS';
@export @export
macro LoadContextElement(c: Context, i: intptr): Object { macro LoadContextElement(c: Context, i: intptr): Object {
return c.elements[i]; return c.elements[i];
......
...@@ -16,7 +16,8 @@ extern class JSArrayIterator extends JSObject { ...@@ -16,7 +16,8 @@ extern class JSArrayIterator extends JSObject {
macro CreateArrayIterator(implicit context: NativeContext)( macro CreateArrayIterator(implicit context: NativeContext)(
array: JSReceiver, kind: constexpr IterationKind): JSArrayIterator { array: JSReceiver, kind: constexpr IterationKind): JSArrayIterator {
return new JSArrayIterator{ return new JSArrayIterator{
map: *NativeContextSlot(ContextSlot::INITIAL_ARRAY_ITERATOR_MAP_INDEX), map: UnsafeCast<Map>(
context.elements[NativeContextSlot::INITIAL_ARRAY_ITERATOR_MAP_INDEX]),
properties_or_hash: kEmptyFixedArray, properties_or_hash: kEmptyFixedArray,
elements: kEmptyFixedArray, elements: kEmptyFixedArray,
iterated_object: array, iterated_object: array,
......
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
extern class ScopeInfo extends FixedArray; extern class ScopeInfo extends FixedArray;
extern macro EmptyScopeInfoConstant(): ScopeInfo;
const kEmptyScopeInfo: ScopeInfo = EmptyScopeInfoConstant();
const kScopeInfoFlagsIndex: const kScopeInfoFlagsIndex:
constexpr int32 generates 'ScopeInfo::Fields::kFlags'; constexpr int32 generates 'ScopeInfo::Fields::kFlags';
......
...@@ -374,10 +374,8 @@ Callable* DeclarationVisitor::Specialize( ...@@ -374,10 +374,8 @@ Callable* DeclarationVisitor::Specialize(
} }
void PredeclarationVisitor::ResolvePredeclarations() { void PredeclarationVisitor::ResolvePredeclarations() {
const auto& all_declarables = GlobalContext::AllDeclarables(); for (auto& p : GlobalContext::AllDeclarables()) {
for (size_t i = 0; i < all_declarables.size(); ++i) { if (const TypeAlias* alias = TypeAlias::DynamicCast(p.get())) {
Declarable* declarable = all_declarables[i].get();
if (const TypeAlias* alias = TypeAlias::DynamicCast(declarable)) {
CurrentScope::Scope scope_activator(alias->ParentScope()); CurrentScope::Scope scope_activator(alias->ParentScope());
CurrentSourcePosition::Scope position_activator(alias->Position()); CurrentSourcePosition::Scope position_activator(alias->Position());
alias->Resolve(); alias->Resolve();
......
...@@ -81,7 +81,12 @@ void ImplementationVisitor::BeginCSAFiles() { ...@@ -81,7 +81,12 @@ void ImplementationVisitor::BeginCSAFiles() {
UnderlinifyPath(SourceFileMap::PathFromV8Root(file)) + "_H_"; UnderlinifyPath(SourceFileMap::PathFromV8Root(file)) + "_H_";
header << "#ifndef " << headerDefine << "\n"; header << "#ifndef " << headerDefine << "\n";
header << "#define " << headerDefine << "\n\n"; header << "#define " << headerDefine << "\n\n";
header << "#include \"src/builtins/torque-csa-header-includes.h\"\n"; header << "#include \"src/builtins/builtins-promise.h\"\n";
header << "#include \"src/compiler/code-assembler.h\"\n";
header << "#include \"src/codegen/code-stub-assembler.h\"\n";
header << "#include \"src/utils/utils.h\"\n";
header << "#include \"torque-generated/field-offsets-tq.h\"\n";
header << "#include \"torque-generated/csa-types-tq.h\"\n";
header << "\n"; header << "\n";
header << "namespace v8 {\n" header << "namespace v8 {\n"
......
...@@ -1306,8 +1306,9 @@ macro TestGeneratedCastOperators(implicit context: Context)() { ...@@ -1306,8 +1306,9 @@ macro TestGeneratedCastOperators(implicit context: Context)() {
assert(!Is<ExportedSubClass>(cO)); assert(!Is<ExportedSubClass>(cO));
assert(Is<ExportedSubClass2>(cO)); assert(Is<ExportedSubClass2>(cO));
const jsf: JSFunction = const nativeContext = LoadNativeContext(context);
*NativeContextSlot(ContextSlot::REGEXP_FUNCTION_INDEX); const jsf: JSFunction = UnsafeCast<JSFunction>(
nativeContext.elements[NativeContextSlot::REGEXP_FUNCTION_INDEX]);
assert(!Is<JSSloppyArgumentsObject>(jsf)); assert(!Is<JSSloppyArgumentsObject>(jsf));
const parameterValues = NewFixedArray(0, ConstantIterator(TheHole)); const parameterValues = NewFixedArray(0, ConstantIterator(TheHole));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment