Commit fdc9fade authored by Nico Hartmann's avatar Nico Hartmann Committed by Commit Bot

[torque] Enum language feature

This CL implements enums in Torque in three steps:

1.) It implements necessary changes to Torque's type system. In
particular, the constraints on constexpr types are relaxed such that
constexpr types can exist without a corresponding non-constexpr
version. Furthermore, constexpr and their non-constexpr counterpart
need not be of the same kind of type. This allows an AbstractType to
have a UnionType as its non-constexpr counterpart.

2.) The enum feature itself is realized as a pure desugaring in the
parser, where all required types, constants and macro specializations
(like FromConstexpr<>) are generated from a simple enum declaration,
such that enum entries are not just constants, but are namespace
scoped and have distinct types so that they can be used within
typeswitch constructs.

3.) Almost all of the existing constants defined in torque
(.tq files) are ported to new enum definitions.

Bug: v8:10053
Change-Id: I72426d3b1434f301fd690847e15603de0dc1021b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1964392
Commit-Queue: Nico Hartmann <nicohartmann@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65503}
parent 15fce7c3
...@@ -75,7 +75,7 @@ namespace array { ...@@ -75,7 +75,7 @@ namespace array {
SetProperty(object, to, fromVal); SetProperty(object, to, fromVal);
} else { } else {
// i. Perform ? DeletePropertyOrThrow(O, toKey). // i. Perform ? DeletePropertyOrThrow(O, toKey).
DeleteProperty(object, to, kStrict); DeleteProperty(object, to, LanguageMode::kStrict);
} }
// f. Let from be from + direction. // f. Let from be from + direction.
......
...@@ -141,7 +141,7 @@ namespace array { ...@@ -141,7 +141,7 @@ namespace array {
} }
} }
label TypeError deferred { label TypeError deferred {
ThrowTypeError(kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} }
} }
} }
...@@ -141,7 +141,7 @@ namespace array { ...@@ -141,7 +141,7 @@ namespace array {
const o = Cast<FastJSArray>(receiver) otherwise Slow; const o = Cast<FastJSArray>(receiver) otherwise Slow;
const newMap: Map = const newMap: Map =
LoadJSArrayElementsMap(o.map.elements_kind, LoadNativeContext(context)); LoadJSArrayElementsMap(o.map.elements_kind, LoadNativeContext(context));
return AllocateJSArray(PACKED_SMI_ELEMENTS, newMap, len, len); return AllocateJSArray(ElementsKind::PACKED_SMI_ELEMENTS, newMap, len, len);
} }
// https://tc39.github.io/ecma262/#sec-array.prototype.filter // https://tc39.github.io/ecma262/#sec-array.prototype.filter
...@@ -196,7 +196,7 @@ namespace array { ...@@ -196,7 +196,7 @@ namespace array {
o, callbackfn, thisArg, output, o, k, len, to); o, callbackfn, thisArg, output, o, k, len, to);
} }
label TypeError deferred { label TypeError deferred {
ThrowTypeError(kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} }
} }
} }
...@@ -148,7 +148,7 @@ namespace array { ...@@ -148,7 +148,7 @@ namespace array {
} }
} }
label NotCallableError deferred { label NotCallableError deferred {
ThrowTypeError(kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} }
} }
} }
...@@ -150,7 +150,7 @@ namespace array { ...@@ -150,7 +150,7 @@ namespace array {
} }
} }
label NotCallableError deferred { label NotCallableError deferred {
ThrowTypeError(kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} }
} }
} }
...@@ -125,7 +125,7 @@ namespace array { ...@@ -125,7 +125,7 @@ namespace array {
o, callbackfn, thisArg, Undefined, o, k, len, Undefined); o, callbackfn, thisArg, Undefined, o, k, len, Undefined);
} }
label TypeError deferred { label TypeError deferred {
ThrowTypeError(kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} }
} }
} }
...@@ -77,7 +77,7 @@ namespace array { ...@@ -77,7 +77,7 @@ namespace array {
return ToString_Inline(result); return ToString_Inline(result);
} }
label TypeError { label TypeError {
ThrowTypeError(kCalledNonCallable, prop); ThrowTypeError(MessageTemplate::kCalledNonCallable, prop);
} }
} }
...@@ -135,8 +135,9 @@ namespace array { ...@@ -135,8 +135,9 @@ namespace array {
deferred { deferred {
const newLength: intptr = CalculateNewElementsCapacity(length); const newLength: intptr = CalculateNewElementsCapacity(length);
assert(index < newLength); assert(index < newLength);
const newfixedArray: FixedArray = const newfixedArray: FixedArray = ExtractFixedArray(
ExtractFixedArray(fixedArray, 0, length, newLength, kFixedArrays); fixedArray, 0, length, newLength,
ExtractFixedArrayFlag::kFixedArrays);
newfixedArray.objects[index] = element; newfixedArray.objects[index] = element;
return newfixedArray; return newfixedArray;
} }
...@@ -335,11 +336,12 @@ namespace array { ...@@ -335,11 +336,12 @@ namespace array {
if (!IsPrototypeInitialArrayPrototype(map)) goto IfSlowPath; if (!IsPrototypeInitialArrayPrototype(map)) goto IfSlowPath;
if (IsNoElementsProtectorCellInvalid()) goto IfSlowPath; if (IsNoElementsProtectorCellInvalid()) goto IfSlowPath;
if (IsElementsKindLessThanOrEqual(kind, HOLEY_ELEMENTS)) { if (IsElementsKindLessThanOrEqual(kind, ElementsKind::HOLEY_ELEMENTS)) {
loadFn = LoadJoinElement<array::FastSmiOrObjectElements>; loadFn = LoadJoinElement<array::FastSmiOrObjectElements>;
} else if (IsElementsKindLessThanOrEqual(kind, HOLEY_DOUBLE_ELEMENTS)) { } else if (IsElementsKindLessThanOrEqual(
kind, ElementsKind::HOLEY_DOUBLE_ELEMENTS)) {
loadFn = LoadJoinElement<array::FastDoubleElements>; loadFn = LoadJoinElement<array::FastDoubleElements>;
} else if (kind == DICTIONARY_ELEMENTS) } else if (kind == ElementsKind::DICTIONARY_ELEMENTS)
deferred { deferred {
const dict: NumberDictionary = const dict: NumberDictionary =
UnsafeCast<NumberDictionary>(array.elements); UnsafeCast<NumberDictionary>(array.elements);
...@@ -376,32 +378,32 @@ namespace array { ...@@ -376,32 +378,32 @@ namespace array {
const kind: ElementsKind = map.elements_kind; const kind: ElementsKind = map.elements_kind;
let loadFn: LoadJoinElementFn; let loadFn: LoadJoinElementFn;
if (IsElementsKindGreaterThan(kind, UINT32_ELEMENTS)) { if (IsElementsKindGreaterThan(kind, ElementsKind::UINT32_ELEMENTS)) {
if (kind == INT32_ELEMENTS) { if (kind == ElementsKind::INT32_ELEMENTS) {
loadFn = LoadJoinTypedElement<typed_array::Int32Elements>; loadFn = LoadJoinTypedElement<typed_array::Int32Elements>;
} else if (kind == FLOAT32_ELEMENTS) { } else if (kind == ElementsKind::FLOAT32_ELEMENTS) {
loadFn = LoadJoinTypedElement<typed_array::Float32Elements>; loadFn = LoadJoinTypedElement<typed_array::Float32Elements>;
} else if (kind == FLOAT64_ELEMENTS) { } else if (kind == ElementsKind::FLOAT64_ELEMENTS) {
loadFn = LoadJoinTypedElement<typed_array::Float64Elements>; loadFn = LoadJoinTypedElement<typed_array::Float64Elements>;
} else if (kind == UINT8_CLAMPED_ELEMENTS) { } else if (kind == ElementsKind::UINT8_CLAMPED_ELEMENTS) {
loadFn = LoadJoinTypedElement<typed_array::Uint8ClampedElements>; loadFn = LoadJoinTypedElement<typed_array::Uint8ClampedElements>;
} else if (kind == BIGUINT64_ELEMENTS) { } else if (kind == ElementsKind::BIGUINT64_ELEMENTS) {
loadFn = LoadJoinTypedElement<typed_array::BigUint64Elements>; loadFn = LoadJoinTypedElement<typed_array::BigUint64Elements>;
} else if (kind == BIGINT64_ELEMENTS) { } else if (kind == ElementsKind::BIGINT64_ELEMENTS) {
loadFn = LoadJoinTypedElement<typed_array::BigInt64Elements>; loadFn = LoadJoinTypedElement<typed_array::BigInt64Elements>;
} else { } else {
unreachable; unreachable;
} }
} else { } else {
if (kind == UINT8_ELEMENTS) { if (kind == ElementsKind::UINT8_ELEMENTS) {
loadFn = LoadJoinTypedElement<typed_array::Uint8Elements>; loadFn = LoadJoinTypedElement<typed_array::Uint8Elements>;
} else if (kind == INT8_ELEMENTS) { } else if (kind == ElementsKind::INT8_ELEMENTS) {
loadFn = LoadJoinTypedElement<typed_array::Int8Elements>; loadFn = LoadJoinTypedElement<typed_array::Int8Elements>;
} else if (kind == UINT16_ELEMENTS) { } else if (kind == ElementsKind::UINT16_ELEMENTS) {
loadFn = LoadJoinTypedElement<typed_array::Uint16Elements>; loadFn = LoadJoinTypedElement<typed_array::Uint16Elements>;
} else if (kind == INT16_ELEMENTS) { } else if (kind == ElementsKind::INT16_ELEMENTS) {
loadFn = LoadJoinTypedElement<typed_array::Int16Elements>; loadFn = LoadJoinTypedElement<typed_array::Int16Elements>;
} else if (kind == UINT32_ELEMENTS) { } else if (kind == ElementsKind::UINT32_ELEMENTS) {
loadFn = LoadJoinTypedElement<typed_array::Uint32Elements>; loadFn = LoadJoinTypedElement<typed_array::Uint32Elements>;
} else { } else {
unreachable; unreachable;
...@@ -421,8 +423,8 @@ namespace array { ...@@ -421,8 +423,8 @@ namespace array {
macro LoadJoinStack(implicit context: Context)(): FixedArray macro LoadJoinStack(implicit context: Context)(): FixedArray
labels IfUninitialized { labels IfUninitialized {
const nativeContext: NativeContext = LoadNativeContext(context); const nativeContext: NativeContext = LoadNativeContext(context);
const stack: HeapObject = const stack: HeapObject = UnsafeCast<HeapObject>(
UnsafeCast<HeapObject>(nativeContext[ARRAY_JOIN_STACK_INDEX]); nativeContext[NativeContextSlot::ARRAY_JOIN_STACK_INDEX]);
if (stack == Undefined) goto IfUninitialized; if (stack == Undefined) goto IfUninitialized;
assert(IsFixedArray(stack)); assert(IsFixedArray(stack));
return UnsafeCast<FixedArray>(stack); return UnsafeCast<FixedArray>(stack);
...@@ -430,7 +432,7 @@ namespace array { ...@@ -430,7 +432,7 @@ namespace array {
macro SetJoinStack(implicit context: Context)(stack: FixedArray): void { macro SetJoinStack(implicit context: Context)(stack: FixedArray): void {
const nativeContext: NativeContext = LoadNativeContext(context); const nativeContext: NativeContext = LoadNativeContext(context);
nativeContext[ARRAY_JOIN_STACK_INDEX] = stack; nativeContext[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
...@@ -475,7 +477,7 @@ namespace array { ...@@ -475,7 +477,7 @@ namespace array {
} }
label IfUninitialized { label IfUninitialized {
const stack: FixedArray = const stack: FixedArray =
AllocateFixedArrayWithHoles(kMinJoinStackSize, kNone); AllocateFixedArrayWithHoles(kMinJoinStackSize, AllocationFlag::kNone);
stack.objects[0] = receiver; stack.objects[0] = receiver;
SetJoinStack(stack); SetJoinStack(stack);
} }
...@@ -492,8 +494,8 @@ namespace array { ...@@ -492,8 +494,8 @@ namespace array {
// Shrink the Join Stack if the stack will be empty and is larger than // Shrink the Join Stack if the stack will be empty and is larger than
// the minimum size. // the minimum size.
if (i == 0 && len > kMinJoinStackSize) deferred { if (i == 0 && len > kMinJoinStackSize) deferred {
const newStack: FixedArray = const newStack: FixedArray = AllocateFixedArrayWithHoles(
AllocateFixedArrayWithHoles(kMinJoinStackSize, kNone); kMinJoinStackSize, AllocationFlag::kNone);
SetJoinStack(newStack); SetJoinStack(newStack);
} }
else { else {
...@@ -561,7 +563,8 @@ namespace array { ...@@ -561,7 +563,8 @@ namespace array {
// Only handle valid array lengths. Although the spec allows larger // Only handle valid array lengths. Although the spec allows larger
// values, this matches historical V8 behavior. // values, this matches historical V8 behavior.
if (len > kMaxArrayIndex + 1) ThrowTypeError(kInvalidArrayLength); if (len > kMaxArrayIndex + 1)
ThrowTypeError(MessageTemplate::kInvalidArrayLength);
return CycleProtectedArrayJoin<JSArray>( return CycleProtectedArrayJoin<JSArray>(
false, o, len, separator, Undefined, Undefined); false, o, len, separator, Undefined, Undefined);
...@@ -582,7 +585,8 @@ namespace array { ...@@ -582,7 +585,8 @@ namespace array {
// Only handle valid array lengths. Although the spec allows larger // Only handle valid array lengths. Although the spec allows larger
// values, this matches historical V8 behavior. // values, this matches historical V8 behavior.
if (len > kMaxArrayIndex + 1) ThrowTypeError(kInvalidArrayLength); if (len > kMaxArrayIndex + 1)
ThrowTypeError(MessageTemplate::kInvalidArrayLength);
return CycleProtectedArrayJoin<JSArray>( return CycleProtectedArrayJoin<JSArray>(
true, o, len, ',', locales, options); true, o, len, ',', locales, options);
......
...@@ -98,12 +98,12 @@ namespace array { ...@@ -98,12 +98,12 @@ namespace array {
macro CreateJSArray(implicit context: Context)(validLength: Smi): JSArray { macro CreateJSArray(implicit context: Context)(validLength: Smi): JSArray {
const length: Smi = this.fixedArray.length; const length: Smi = this.fixedArray.length;
assert(validLength <= length); assert(validLength <= length);
let kind: ElementsKind = PACKED_SMI_ELEMENTS; let kind: ElementsKind = ElementsKind::PACKED_SMI_ELEMENTS;
if (!this.onlySmis) { if (!this.onlySmis) {
if (this.onlyNumbers) { if (this.onlyNumbers) {
kind = PACKED_DOUBLE_ELEMENTS; kind = ElementsKind::PACKED_DOUBLE_ELEMENTS;
} else { } else {
kind = PACKED_ELEMENTS; kind = ElementsKind::PACKED_ELEMENTS;
} }
} }
...@@ -124,7 +124,7 @@ namespace array { ...@@ -124,7 +124,7 @@ namespace array {
// First, initialize the elements field before allocation to prevent // First, initialize the elements field before allocation to prevent
// heap corruption. // heap corruption.
const elements: FixedDoubleArray = AllocateFixedDoubleArrayWithHoles( const elements: FixedDoubleArray = AllocateFixedDoubleArrayWithHoles(
SmiUntag(length), kAllowLargeObjectAllocation); SmiUntag(length), AllocationFlag::kAllowLargeObjectAllocation);
a = NewJSArray(map, this.fixedArray); a = NewJSArray(map, this.fixedArray);
for (let i: Smi = 0; i < validLength; i++) { for (let i: Smi = 0; i < validLength; i++) {
typeswitch ( typeswitch (
...@@ -173,7 +173,7 @@ namespace array { ...@@ -173,7 +173,7 @@ namespace array {
macro NewVector(implicit context: Context)(length: Smi): Vector { macro NewVector(implicit context: Context)(length: Smi): Vector {
const fixedArray = length > 0 ? const fixedArray = length > 0 ?
AllocateFixedArrayWithHoles( AllocateFixedArrayWithHoles(
SmiUntag(length), kAllowLargeObjectAllocation) : SmiUntag(length), AllocationFlag::kAllowLargeObjectAllocation) :
kEmptyFixedArray; kEmptyFixedArray;
return Vector{ return Vector{
fixedArray, fixedArray,
...@@ -267,7 +267,7 @@ namespace array { ...@@ -267,7 +267,7 @@ namespace array {
return ArrayMapLoopContinuation(o, callbackfn, thisArg, array, o, k, len); return ArrayMapLoopContinuation(o, callbackfn, thisArg, array, o, k, len);
} }
label TypeError deferred { label TypeError deferred {
ThrowTypeError(kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} }
} }
} }
...@@ -109,7 +109,8 @@ namespace array { ...@@ -109,7 +109,8 @@ namespace array {
// this means kPresent is false. // this means kPresent is false.
typeswitch (accumulator) { typeswitch (accumulator) {
case (TheHole): { case (TheHole): {
ThrowTypeError(kReduceNoInitial, 'Array.prototype.reduceRight'); ThrowTypeError(
MessageTemplate::kReduceNoInitial, 'Array.prototype.reduceRight');
} }
case (accumulator: JSAny): { case (accumulator: JSAny): {
return accumulator; return accumulator;
...@@ -148,7 +149,8 @@ namespace array { ...@@ -148,7 +149,8 @@ namespace array {
} }
typeswitch (accumulator) { typeswitch (accumulator) {
case (TheHole): { case (TheHole): {
ThrowTypeError(kReduceNoInitial, 'Array.prototype.reduceRight'); ThrowTypeError(
MessageTemplate::kReduceNoInitial, 'Array.prototype.reduceRight');
} }
case (accumulator: JSAny): { case (accumulator: JSAny): {
return accumulator; return accumulator;
...@@ -192,7 +194,7 @@ namespace array { ...@@ -192,7 +194,7 @@ namespace array {
} }
} }
label NoCallableError deferred { label NoCallableError deferred {
ThrowTypeError(kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} }
} }
} }
...@@ -107,7 +107,8 @@ namespace array { ...@@ -107,7 +107,8 @@ namespace array {
// this means kPresent is false. // this means kPresent is false.
typeswitch (accumulator) { typeswitch (accumulator) {
case (TheHole): { case (TheHole): {
ThrowTypeError(kReduceNoInitial, 'Array.prototype.reduce'); ThrowTypeError(
MessageTemplate::kReduceNoInitial, 'Array.prototype.reduce');
} }
case (accumulator: JSAny): { case (accumulator: JSAny): {
return accumulator; return accumulator;
...@@ -147,7 +148,8 @@ namespace array { ...@@ -147,7 +148,8 @@ namespace array {
} }
typeswitch (accumulator) { typeswitch (accumulator) {
case (TheHole): { case (TheHole): {
ThrowTypeError(kReduceNoInitial, 'Array.prototype.reduce'); ThrowTypeError(
MessageTemplate::kReduceNoInitial, 'Array.prototype.reduce');
} }
case (accumulator: JSAny): { case (accumulator: JSAny): {
return accumulator; return accumulator;
...@@ -191,7 +193,7 @@ namespace array { ...@@ -191,7 +193,7 @@ namespace array {
} }
} }
label NoCallableError deferred { label NoCallableError deferred {
ThrowTypeError(kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} }
} }
} }
...@@ -124,10 +124,10 @@ namespace array { ...@@ -124,10 +124,10 @@ namespace array {
SetProperty(object, lower, upperValue); SetProperty(object, lower, upperValue);
// ii. Perform ? DeletePropertyOrThrow(O, upperP). // ii. Perform ? DeletePropertyOrThrow(O, upperP).
DeleteProperty(object, upper, kStrict); DeleteProperty(object, upper, LanguageMode::kStrict);
} else if (lowerExists == True && upperExists == False) { } else if (lowerExists == True && upperExists == False) {
// i. Perform ? DeletePropertyOrThrow(O, lowerP). // i. Perform ? DeletePropertyOrThrow(O, lowerP).
DeleteProperty(object, lower, kStrict); DeleteProperty(object, lower, LanguageMode::kStrict);
// ii. Perform ? Set(O, upperP, lowerValue, true). // ii. Perform ? Set(O, upperP, lowerValue, true).
SetProperty(object, upper, lowerValue); SetProperty(object, upper, lowerValue);
...@@ -147,15 +147,15 @@ namespace array { ...@@ -147,15 +147,15 @@ namespace array {
const array: FastJSArray = Cast<FastJSArray>(receiver) otherwise Slow; const array: FastJSArray = Cast<FastJSArray>(receiver) otherwise Slow;
const kind: ElementsKind = array.map.elements_kind; const kind: ElementsKind = array.map.elements_kind;
if (kind == PACKED_SMI_ELEMENTS) { if (kind == ElementsKind::PACKED_SMI_ELEMENTS) {
array::EnsureWriteableFastElements(array); array::EnsureWriteableFastElements(array);
FastPackedArrayReverse<array::FastPackedSmiElements, Smi>( FastPackedArrayReverse<array::FastPackedSmiElements, Smi>(
array.elements, array.length); array.elements, array.length);
} else if (kind == PACKED_ELEMENTS) { } else if (kind == ElementsKind::PACKED_ELEMENTS) {
array::EnsureWriteableFastElements(array); array::EnsureWriteableFastElements(array);
FastPackedArrayReverse<array::FastPackedObjectElements, JSAny>( FastPackedArrayReverse<array::FastPackedObjectElements, JSAny>(
array.elements, array.length); array.elements, array.length);
} else if (kind == PACKED_DOUBLE_ELEMENTS) { } else if (kind == ElementsKind::PACKED_DOUBLE_ELEMENTS) {
FastPackedArrayReverse<array::FastPackedDoubleElements, float64>( FastPackedArrayReverse<array::FastPackedDoubleElements, float64>(
array.elements, array.length); array.elements, array.length);
} else { } else {
......
...@@ -76,7 +76,7 @@ namespace array { ...@@ -76,7 +76,7 @@ namespace array {
SetProperty(object, to, fromValue); SetProperty(object, to, fromValue);
} else { } else {
// i. Perform ? DeletePropertyOrThrow(O, to). // i. Perform ? DeletePropertyOrThrow(O, to).
DeleteProperty(object, to, kStrict); DeleteProperty(object, to, LanguageMode::kStrict);
} }
// f. Increase k by 1. // f. Increase k by 1.
...@@ -84,7 +84,7 @@ namespace array { ...@@ -84,7 +84,7 @@ namespace array {
} }
// 7. Perform ? DeletePropertyOrThrow(O, ! ToString(len - 1)). // 7. Perform ? DeletePropertyOrThrow(O, ! ToString(len - 1)).
DeleteProperty(object, length - 1, kStrict); DeleteProperty(object, length - 1, LanguageMode::kStrict);
// 8. Perform ? Set(O, "length", len - 1, true). // 8. Perform ? Set(O, "length", len - 1, true).
SetProperty(object, kLengthString, length - 1); SetProperty(object, kLengthString, length - 1);
......
...@@ -15,14 +15,15 @@ namespace array { ...@@ -15,14 +15,15 @@ namespace array {
Cast<FixedArray>(args.elements) otherwise Bailout; Cast<FixedArray>(args.elements) otherwise Bailout;
if (SmiAbove(end, sourceElements.length)) goto Bailout; if (SmiAbove(end, sourceElements.length)) goto Bailout;
const arrayMap: Map = LoadJSArrayElementsMap(HOLEY_ELEMENTS, context); const arrayMap: Map =
LoadJSArrayElementsMap(ElementsKind::HOLEY_ELEMENTS, context);
const result: JSArray = const result: JSArray =
AllocateJSArray(HOLEY_ELEMENTS, arrayMap, count, count); AllocateJSArray(ElementsKind::HOLEY_ELEMENTS, arrayMap, count, count);
const newElements: FixedArray = const newElements: FixedArray =
Cast<FixedArray>(result.elements) otherwise Bailout; Cast<FixedArray>(result.elements) otherwise Bailout;
CopyElements( CopyElements(
PACKED_ELEMENTS, newElements, 0, sourceElements, Convert<intptr>(start), ElementsKind::PACKED_ELEMENTS, newElements, 0, sourceElements,
Convert<intptr>(count)); Convert<intptr>(start), Convert<intptr>(count));
return result; return result;
} }
...@@ -51,9 +52,10 @@ namespace array { ...@@ -51,9 +52,10 @@ namespace array {
const argumentsContext: Context = UnsafeCast<Context>( const argumentsContext: Context = UnsafeCast<Context>(
sloppyElements.objects[kSloppyArgumentsContextIndex]); sloppyElements.objects[kSloppyArgumentsContextIndex]);
const arrayMap: Map = LoadJSArrayElementsMap(HOLEY_ELEMENTS, context); const arrayMap: Map =
LoadJSArrayElementsMap(ElementsKind::HOLEY_ELEMENTS, context);
const result: JSArray = const result: JSArray =
AllocateJSArray(HOLEY_ELEMENTS, arrayMap, count, count); AllocateJSArray(ElementsKind::HOLEY_ELEMENTS, arrayMap, count, count);
let indexOut: Smi = 0; let indexOut: Smi = 0;
const resultElements: FixedArray = UnsafeCast<FixedArray>(result.elements); const resultElements: FixedArray = UnsafeCast<FixedArray>(result.elements);
...@@ -79,9 +81,9 @@ namespace array { ...@@ -79,9 +81,9 @@ namespace array {
const unmappedFrom: Smi = SmiMin(SmiMax(parameterMapLength, start), end); const unmappedFrom: Smi = SmiMin(SmiMax(parameterMapLength, start), end);
const restCount: Smi = end - unmappedFrom; const restCount: Smi = end - unmappedFrom;
CopyElements( CopyElements(
PACKED_ELEMENTS, resultElements, Convert<intptr>(indexOut), ElementsKind::PACKED_ELEMENTS, resultElements,
unmappedElements, Convert<intptr>(unmappedFrom), Convert<intptr>(indexOut), unmappedElements,
Convert<intptr>(restCount)); Convert<intptr>(unmappedFrom), Convert<intptr>(restCount));
return result; return result;
} }
......
...@@ -141,7 +141,7 @@ namespace array { ...@@ -141,7 +141,7 @@ namespace array {
} }
} }
label TypeError deferred { label TypeError deferred {
ThrowTypeError(kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} }
} }
} }
...@@ -240,7 +240,7 @@ namespace array { ...@@ -240,7 +240,7 @@ namespace array {
// v. Else fromPresent is false, // v. Else fromPresent is false,
} else { } else {
// 1. Perform ? DeletePropertyOrThrow(O, to). // 1. Perform ? DeletePropertyOrThrow(O, to).
DeleteProperty(o, to, kStrict); DeleteProperty(o, to, LanguageMode::kStrict);
} }
// vi. Increase k by 1. // vi. Increase k by 1.
k++; k++;
...@@ -252,7 +252,7 @@ namespace array { ...@@ -252,7 +252,7 @@ namespace array {
// d. Repeat, while k > (len - actualDeleteCount + itemCount) // d. Repeat, while k > (len - actualDeleteCount + itemCount)
while (k > (len - actualDeleteCount + itemCount)) { while (k > (len - actualDeleteCount + itemCount)) {
// i. Perform ? DeletePropertyOrThrow(O, ! ToString(k - 1)). // i. Perform ? DeletePropertyOrThrow(O, ! ToString(k - 1)).
DeleteProperty(o, k - 1, kStrict); DeleteProperty(o, k - 1, LanguageMode::kStrict);
// ii. Decrease k by 1. // ii. Decrease k by 1.
k--; k--;
} }
...@@ -289,7 +289,7 @@ namespace array { ...@@ -289,7 +289,7 @@ namespace array {
// v. Else fromPresent is false, // v. Else fromPresent is false,
} else { } else {
// 1. Perform ? DeletePropertyOrThrow(O, to). // 1. Perform ? DeletePropertyOrThrow(O, to).
DeleteProperty(o, to, kStrict); DeleteProperty(o, to, LanguageMode::kStrict);
} }
// vi. Decrease k by 1. // vi. Decrease k by 1.
...@@ -398,7 +398,7 @@ namespace array { ...@@ -398,7 +398,7 @@ namespace array {
// Bailout exception. // Bailout exception.
const newLength: Number = len + insertCount - actualDeleteCount; const newLength: Number = len + insertCount - actualDeleteCount;
if (newLength > kMaxSafeInteger) { if (newLength > kMaxSafeInteger) {
ThrowTypeError(kInvalidArrayLength, start); ThrowTypeError(MessageTemplate::kInvalidArrayLength, start);
} }
try { try {
......
...@@ -20,7 +20,7 @@ namespace array { ...@@ -20,7 +20,7 @@ namespace array {
if (argCount > 0) { if (argCount > 0) {
// a. If len + argCount > 2**53 - 1, throw a TypeError exception. // a. If len + argCount > 2**53 - 1, throw a TypeError exception.
if (length + argCount > kMaxSafeInteger) { if (length + argCount > kMaxSafeInteger) {
ThrowTypeError(kInvalidArrayLength); ThrowTypeError(MessageTemplate::kInvalidArrayLength);
} }
// b. Let k be len. // b. Let k be len.
...@@ -46,7 +46,7 @@ namespace array { ...@@ -46,7 +46,7 @@ namespace array {
SetProperty(object, to, fromValue); SetProperty(object, to, fromValue);
} else { } else {
// 1. Perform ? DeletePropertyOrThrow(O, to). // 1. Perform ? DeletePropertyOrThrow(O, to).
DeleteProperty(object, to, kStrict); DeleteProperty(object, to, LanguageMode::kStrict);
} }
// vi. Decrease k by 1. // vi. Decrease k by 1.
......
...@@ -27,8 +27,8 @@ namespace array { ...@@ -27,8 +27,8 @@ namespace array {
assert(IsFastSmiOrTaggedElementsKind(array.map.elements_kind)); assert(IsFastSmiOrTaggedElementsKind(array.map.elements_kind));
const length: Smi = Cast<Smi>(array.length) otherwise unreachable; const length: Smi = Cast<Smi>(array.length) otherwise unreachable;
array.elements = array.elements = ExtractFixedArray(
ExtractFixedArray(elements, 0, length, length, kFixedArrays); elements, 0, length, length, ExtractFixedArrayFlag::kFixedArrays);
assert(array.elements.map != kCOWMap); assert(array.elements.map != kCOWMap);
} }
......
This diff is collapsed.
...@@ -74,7 +74,7 @@ namespace bigint { ...@@ -74,7 +74,7 @@ namespace bigint {
return AllocateEmptyBigIntNoThrow(sign, length) otherwise BigIntTooBig; return AllocateEmptyBigIntNoThrow(sign, length) otherwise BigIntTooBig;
} }
label BigIntTooBig { label BigIntTooBig {
ThrowRangeError(kBigIntTooBig); ThrowRangeError(MessageTemplate::kBigIntTooBig);
} }
} }
...@@ -176,10 +176,10 @@ namespace bigint { ...@@ -176,10 +176,10 @@ namespace bigint {
return BigIntAddImpl(x, y) otherwise BigIntTooBig; return BigIntAddImpl(x, y) otherwise BigIntTooBig;
} }
label MixedTypes { label MixedTypes {
ThrowTypeError(kBigIntMixedTypes); ThrowTypeError(MessageTemplate::kBigIntMixedTypes);
} }
label BigIntTooBig { label BigIntTooBig {
ThrowRangeError(kBigIntTooBig); ThrowRangeError(MessageTemplate::kBigIntTooBig);
} }
} }
...@@ -221,10 +221,10 @@ namespace bigint { ...@@ -221,10 +221,10 @@ namespace bigint {
return BigIntSubtractImpl(x, y) otherwise BigIntTooBig; return BigIntSubtractImpl(x, y) otherwise BigIntTooBig;
} }
label MixedTypes { label MixedTypes {
ThrowTypeError(kBigIntMixedTypes); ThrowTypeError(MessageTemplate::kBigIntMixedTypes);
} }
label BigIntTooBig { label BigIntTooBig {
ThrowRangeError(kBigIntTooBig); ThrowRangeError(MessageTemplate::kBigIntTooBig);
} }
} }
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
namespace boolean { namespace boolean {
transitioning macro ThisBooleanValue(implicit context: Context)( transitioning macro ThisBooleanValue(implicit context: Context)(
receiver: JSAny, method: constexpr string): Boolean { receiver: JSAny, method: constexpr string): Boolean {
return UnsafeCast<Boolean>(ToThisValue(receiver, kBoolean, method)); return UnsafeCast<Boolean>(
ToThisValue(receiver, PrimitiveType::kBoolean, method));
} }
javascript builtin javascript builtin
......
...@@ -12,14 +12,16 @@ namespace string { ...@@ -12,14 +12,16 @@ namespace string {
transitioning javascript builtin transitioning javascript builtin
StringPrototypeToString( StringPrototypeToString(
js-implicit context: NativeContext, receiver: JSAny)(): JSAny { js-implicit context: NativeContext, receiver: JSAny)(): JSAny {
return ToThisValue(receiver, kString, 'String.prototype.toString'); return ToThisValue(
receiver, PrimitiveType::kString, 'String.prototype.toString');
} }
// ES6 #sec-string.prototype.valueof // ES6 #sec-string.prototype.valueof
transitioning javascript builtin transitioning javascript builtin
StringPrototypeValueOf(js-implicit context: NativeContext, receiver: JSAny)(): StringPrototypeValueOf(js-implicit context: NativeContext, receiver: JSAny)():
JSAny { JSAny {
return ToThisValue(receiver, kString, 'String.prototype.valueOf'); return ToThisValue(
receiver, PrimitiveType::kString, 'String.prototype.valueOf');
} }
extern macro StringBuiltinsAssembler::LoadSurrogatePairAt( extern macro StringBuiltinsAssembler::LoadSurrogatePairAt(
...@@ -30,16 +32,16 @@ namespace string { ...@@ -30,16 +32,16 @@ namespace string {
// This function assumes StringPrimitiveWithNoCustomIteration is true. // This function assumes StringPrimitiveWithNoCustomIteration is true.
transitioning builtin StringToList(implicit context: Context)(string: String): transitioning builtin StringToList(implicit context: Context)(string: String):
JSArray { JSArray {
const kind = PACKED_ELEMENTS; const kind = ElementsKind::PACKED_ELEMENTS;
const stringLength: intptr = string.length_intptr; const stringLength: intptr = string.length_intptr;
const nativeContext = LoadNativeContext(context); const nativeContext = LoadNativeContext(context);
const map: Map = LoadJSArrayElementsMap(kind, nativeContext); const map: Map = LoadJSArrayElementsMap(kind, nativeContext);
const array: JSArray = AllocateJSArray( const array: JSArray = AllocateJSArray(
kind, map, stringLength, SmiTag(stringLength), kind, map, stringLength, SmiTag(stringLength),
kAllowLargeObjectAllocation); AllocationFlag::kAllowLargeObjectAllocation);
const elements = UnsafeCast<FixedArray>(array.elements); const elements = UnsafeCast<FixedArray>(array.elements);
const encoding = UTF16; const encoding = UnicodeEncoding::UTF16;
let arrayLength: Smi = 0; let arrayLength: Smi = 0;
let i: intptr = 0; let i: intptr = 0;
while (i < stringLength) { while (i < stringLength) {
...@@ -136,8 +138,8 @@ namespace string { ...@@ -136,8 +138,8 @@ namespace string {
label IfInBounds(string: String, index: uintptr, length: uintptr) { label IfInBounds(string: String, index: uintptr, length: uintptr) {
// This is always a call to a builtin from Javascript, so we need to // This is always a call to a builtin from Javascript, so we need to
// produce UTF32. // produce UTF32.
const code: int32 = const code: int32 = LoadSurrogatePairAt(
LoadSurrogatePairAt(string, Signed(length), Signed(index), UTF32); string, Signed(length), Signed(index), UnicodeEncoding::UTF32);
return Convert<Smi>(code); return Convert<Smi>(code);
} }
label IfOutOfBounds { label IfOutOfBounds {
......
...@@ -541,7 +541,7 @@ Cast<FastJSArrayForRead>(implicit context: Context)(o: HeapObject): ...@@ -541,7 +541,7 @@ Cast<FastJSArrayForRead>(implicit context: Context)(o: HeapObject):
// Bailout if receiver has slow elements. // Bailout if receiver has slow elements.
const elementsKind: ElementsKind = LoadMapElementsKind(map); const elementsKind: ElementsKind = LoadMapElementsKind(map);
if (!IsElementsKindLessThanOrEqual( if (!IsElementsKindLessThanOrEqual(
elementsKind, LAST_ANY_NONEXTENSIBLE_ELEMENTS_KIND)) elementsKind, ElementsKind::LAST_ANY_NONEXTENSIBLE_ELEMENTS_KIND))
goto CastError; goto CastError;
// Verify that our prototype is the initial array prototype. // Verify that our prototype is the initial array prototype.
......
...@@ -37,7 +37,7 @@ namespace collections { ...@@ -37,7 +37,7 @@ namespace collections {
goto MayHaveSideEffects; goto MayHaveSideEffects;
} }
case (o: JSAny): deferred { case (o: JSAny): deferred {
ThrowTypeError(kIteratorValueNotAnObject, o); ThrowTypeError(MessageTemplate::kIteratorValueNotAnObject, o);
} }
} }
} }
......
...@@ -71,32 +71,16 @@ FromConstexpr<float64, constexpr float64>(i: constexpr float64): float64 { ...@@ -71,32 +71,16 @@ FromConstexpr<float64, constexpr float64>(i: constexpr float64): float64 {
FromConstexpr<bool, constexpr bool>(b: constexpr bool): bool { FromConstexpr<bool, constexpr bool>(b: constexpr bool): bool {
return BoolConstant(b); return BoolConstant(b);
} }
FromConstexpr<LanguageMode, constexpr LanguageMode>(m: constexpr LanguageMode):
LanguageMode {
return %RawDownCast<LanguageMode>(%FromConstexpr<Smi>(m));
}
FromConstexpr<ElementsKind, constexpr ElementsKind>(e: constexpr ElementsKind):
ElementsKind {
return Int32Constant(e);
}
FromConstexpr<Object, constexpr string>(s: constexpr string): Object { FromConstexpr<Object, constexpr string>(s: constexpr string): Object {
return StringConstant(s); return StringConstant(s);
} }
FromConstexpr<JSAny, constexpr string>(s: constexpr string): JSAny { FromConstexpr<JSAny, constexpr string>(s: constexpr string): JSAny {
return StringConstant(s); return StringConstant(s);
} }
FromConstexpr<NativeContextSlot, constexpr NativeContextSlot>(
c: constexpr NativeContextSlot): NativeContextSlot {
return IntPtrConstant(c);
}
FromConstexpr<ContextSlot, constexpr ContextSlot>(c: constexpr ContextSlot): FromConstexpr<ContextSlot, constexpr ContextSlot>(c: constexpr ContextSlot):
ContextSlot { ContextSlot {
return IntPtrConstant(c); return IntPtrConstant(c);
} }
FromConstexpr<PromiseState, constexpr PromiseState>(s: constexpr PromiseState):
PromiseState {
return %FromConstexpr<PromiseState>(s);
}
macro Convert<To: type, From: type>(i: From): To { macro Convert<To: type, From: type>(i: From): To {
return i; return i;
......
This diff is collapsed.
...@@ -15,7 +15,8 @@ namespace growable_fixed_array { ...@@ -15,7 +15,8 @@ namespace growable_fixed_array {
assert(newCapacity >= this.length); assert(newCapacity >= this.length);
const first: intptr = 0; const first: intptr = 0;
return ExtractFixedArray( return ExtractFixedArray(
this.array, first, this.length, newCapacity, kFixedArrays); this.array, first, this.length, newCapacity,
ExtractFixedArrayFlag::kFixedArrays);
} }
macro EnsureCapacity() { macro EnsureCapacity() {
assert(this.length <= this.capacity); assert(this.length <= this.capacity);
...@@ -28,7 +29,8 @@ namespace growable_fixed_array { ...@@ -28,7 +29,8 @@ namespace growable_fixed_array {
} }
macro ToJSArray(implicit context: Context)(): JSArray { macro ToJSArray(implicit context: Context)(): JSArray {
const nativeContext: NativeContext = LoadNativeContext(context); const nativeContext: NativeContext = LoadNativeContext(context);
const map: Map = LoadJSArrayElementsMap(PACKED_ELEMENTS, nativeContext); const map: Map =
LoadJSArrayElementsMap(ElementsKind::PACKED_ELEMENTS, nativeContext);
const fixedArray: FixedArray = this.ResizeFixedArray(this.length); const fixedArray: FixedArray = this.ResizeFixedArray(this.length);
const lengthSmi = Convert<Smi>(this.length); const lengthSmi = Convert<Smi>(this.length);
return AllocateJSArray(map, fixedArray, lengthSmi); return AllocateJSArray(map, fixedArray, lengthSmi);
......
...@@ -451,17 +451,18 @@ namespace math { ...@@ -451,17 +451,18 @@ namespace math {
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 = Cast<Smi>(context[MATH_RANDOM_INDEX_INDEX]) let smiIndex: Smi =
Cast<Smi>(context[NativeContextSlot::MATH_RANDOM_INDEX_INDEX])
otherwise unreachable; 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;
context[MATH_RANDOM_INDEX_INDEX] = newSmiIndex; context[NativeContextSlot::MATH_RANDOM_INDEX_INDEX] = newSmiIndex;
const array: FixedDoubleArray = const array: FixedDoubleArray = Cast<FixedDoubleArray>(
Cast<FixedDoubleArray>(context[MATH_RANDOM_CACHE_INDEX]) context[NativeContextSlot::MATH_RANDOM_CACHE_INDEX])
otherwise unreachable; otherwise unreachable;
const random: float64 = array.floats[Convert<intptr>(newSmiIndex)]; const random: float64 = array.floats[Convert<intptr>(newSmiIndex)];
return AllocateHeapNumberWithValue(random); return AllocateHeapNumberWithValue(random);
......
...@@ -8,9 +8,6 @@ namespace runtime { ...@@ -8,9 +8,6 @@ namespace runtime {
} // namespace runtime } // namespace runtime
namespace number { namespace number {
const kToRadixFormatRange: constexpr MessageTemplate
generates 'MessageTemplate::kToRadixFormatRange';
extern macro NaNStringConstant(): String; extern macro NaNStringConstant(): String;
extern macro ZeroStringConstant(): String; extern macro ZeroStringConstant(): String;
extern macro InfinityStringConstant(): String; extern macro InfinityStringConstant(): String;
...@@ -21,7 +18,8 @@ namespace number { ...@@ -21,7 +18,8 @@ namespace number {
transitioning macro ThisNumberValue(implicit context: Context)( transitioning macro ThisNumberValue(implicit context: Context)(
receiver: JSAny, method: constexpr string): Number { receiver: JSAny, method: constexpr string): Number {
return UnsafeCast<Number>(ToThisValue(receiver, kNumber, method)); return UnsafeCast<Number>(
ToThisValue(receiver, PrimitiveType::kNumber, method));
} }
// https://tc39.github.io/ecma262/#sec-number.prototype.tostring // https://tc39.github.io/ecma262/#sec-number.prototype.tostring
...@@ -40,7 +38,7 @@ namespace number { ...@@ -40,7 +38,7 @@ namespace number {
// 5. If radixNumber < 2 or radixNumber > 36, throw a RangeError exception. // 5. If radixNumber < 2 or radixNumber > 36, throw a RangeError exception.
if (radixNumber < 2 || radixNumber > 36) { if (radixNumber < 2 || radixNumber > 36) {
ThrowRangeError(kToRadixFormatRange); ThrowRangeError(MessageTemplate::kToRadixFormatRange);
} }
// 6. If radixNumber = 10, return ! ToString(x). // 6. If radixNumber = 10, return ! ToString(x).
......
...@@ -62,7 +62,7 @@ namespace object { ...@@ -62,7 +62,7 @@ namespace object {
} }
} }
label Throw deferred { label Throw deferred {
ThrowTypeError(kNotIterable); ThrowTypeError(MessageTemplate::kNotIterable);
} }
} }
} // namespace object } // namespace object
...@@ -104,13 +104,14 @@ namespace object { ...@@ -104,13 +104,14 @@ namespace object {
typeswitch (prototype) { typeswitch (prototype) {
case (Null): { case (Null): {
map = UnsafeCast<Map>( map = UnsafeCast<Map>(
nativeContext[SLOW_OBJECT_WITH_NULL_PROTOTYPE_MAP]); nativeContext
[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>(
UnsafeCast<JSFunction>(nativeContext[OBJECT_FUNCTION_INDEX]); nativeContext[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 = const prototypeInfo =
...@@ -173,7 +174,7 @@ namespace object { ...@@ -173,7 +174,7 @@ namespace object {
return object::ObjectSetPrototypeOfThrow(object, proto); return object::ObjectSetPrototypeOfThrow(object, proto);
} }
case (JSAny): { case (JSAny): {
ThrowTypeError(kProtoObjectOrNull, proto); ThrowTypeError(MessageTemplate::kProtoObjectOrNull, proto);
} }
} }
} }
......
...@@ -27,24 +27,6 @@ namespace runtime { ...@@ -27,24 +27,6 @@ namespace runtime {
// https://tc39.es/ecma262/#sec-promise-abstract-operations // https://tc39.es/ecma262/#sec-promise-abstract-operations
namespace promise { namespace promise {
const PROMISE_FUNCTION_INDEX: constexpr NativeContextSlot
generates 'Context::PROMISE_FUNCTION_INDEX';
const STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX: constexpr NativeContextSlot
generates 'Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX';
const PROMISE_CAPABILITY_DEFAULT_RESOLVE_SHARED_FUN_INDEX:
constexpr NativeContextSlot
generates 'Context::PROMISE_CAPABILITY_DEFAULT_RESOLVE_SHARED_FUN_INDEX'
;
const PROMISE_CAPABILITY_DEFAULT_REJECT_SHARED_FUN_INDEX:
constexpr NativeContextSlot
generates 'Context::PROMISE_CAPABILITY_DEFAULT_REJECT_SHARED_FUN_INDEX'
;
const PROMISE_GET_CAPABILITIES_EXECUTOR_SHARED_FUN:
constexpr NativeContextSlot
generates 'Context::PROMISE_GET_CAPABILITIES_EXECUTOR_SHARED_FUN';
const kPromiseNonCallable: constexpr MessageTemplate
generates 'MessageTemplate::kPromiseNonCallable';
extern macro AllocateFunctionWithMapAndContext( extern macro AllocateFunctionWithMapAndContext(
Map, SharedFunctionInfo, Context): JSFunction; Map, SharedFunctionInfo, Context): JSFunction;
...@@ -195,7 +177,7 @@ namespace promise { ...@@ -195,7 +177,7 @@ namespace promise {
FulfillPromise(implicit context: Context)(promise: JSPromise, value: JSAny): FulfillPromise(implicit context: Context)(promise: JSPromise, value: JSAny):
Undefined { Undefined {
// Assert: The value of promise.[[PromiseState]] is "pending". // Assert: The value of promise.[[PromiseState]] is "pending".
assert(promise.Status() == kPromisePending); assert(promise.Status() == PromiseState::kPending);
// 2. Let reactions be promise.[[PromiseFulfillReactions]]. // 2. Let reactions be promise.[[PromiseFulfillReactions]].
const reactions = const reactions =
...@@ -207,7 +189,7 @@ namespace promise { ...@@ -207,7 +189,7 @@ namespace promise {
promise.reactions_or_result = value; promise.reactions_or_result = value;
// 6. Set promise.[[PromiseState]] to "fulfilled". // 6. Set promise.[[PromiseState]] to "fulfilled".
promise.SetStatus(kPromiseFulfilled); promise.SetStatus(PromiseState::kFulfilled);
// 7. Return TriggerPromiseReactions(reactions, value). // 7. Return TriggerPromiseReactions(reactions, value).
TriggerPromiseReactions(reactions, value, kPromiseReactionFulfill); TriggerPromiseReactions(reactions, value, kPromiseReactionFulfill);
...@@ -244,7 +226,7 @@ namespace promise { ...@@ -244,7 +226,7 @@ namespace promise {
promise.reactions_or_result = reason; promise.reactions_or_result = reason;
// 6. Set promise.[[PromiseState]] to "rejected". // 6. Set promise.[[PromiseState]] to "rejected".
promise.SetStatus(kPromiseRejected); promise.SetStatus(PromiseState::kRejected);
// 8. Return TriggerPromiseReactions(reactions, reason). // 8. Return TriggerPromiseReactions(reactions, reason).
TriggerPromiseReactions(reactions, reason, kPromiseReactionReject); TriggerPromiseReactions(reactions, reason, kPromiseReactionReject);
...@@ -305,13 +287,16 @@ namespace promise { ...@@ -305,13 +287,16 @@ namespace promise {
const promiseContext = CreatePromiseResolvingFunctionsContext( const promiseContext = CreatePromiseResolvingFunctionsContext(
promise, debugEvent, nativeContext); promise, debugEvent, nativeContext);
const map = UnsafeCast<Map>( const map = UnsafeCast<Map>(
nativeContext[STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX]); nativeContext
[NativeContextSlot::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX]);
const resolveInfo = UnsafeCast<SharedFunctionInfo>( const resolveInfo = UnsafeCast<SharedFunctionInfo>(
nativeContext[PROMISE_CAPABILITY_DEFAULT_RESOLVE_SHARED_FUN_INDEX]); nativeContext[NativeContextSlot::
PROMISE_CAPABILITY_DEFAULT_RESOLVE_SHARED_FUN_INDEX]);
const resolve: JSFunction = const resolve: JSFunction =
AllocateFunctionWithMapAndContext(map, resolveInfo, promiseContext); AllocateFunctionWithMapAndContext(map, resolveInfo, promiseContext);
const rejectInfo = UnsafeCast<SharedFunctionInfo>( const rejectInfo = UnsafeCast<SharedFunctionInfo>(
nativeContext[PROMISE_CAPABILITY_DEFAULT_REJECT_SHARED_FUN_INDEX]); nativeContext[NativeContextSlot::
PROMISE_CAPABILITY_DEFAULT_REJECT_SHARED_FUN_INDEX]);
const reject: JSFunction = const reject: JSFunction =
AllocateFunctionWithMapAndContext(map, rejectInfo, promiseContext); AllocateFunctionWithMapAndContext(map, rejectInfo, promiseContext);
return PromiseResolvingFunctions{resolve: resolve, reject: reject}; return PromiseResolvingFunctions{resolve: resolve, reject: reject};
...@@ -321,7 +306,9 @@ namespace promise { ...@@ -321,7 +306,9 @@ namespace promise {
InnerNewPromiseCapability(implicit context: Context)( InnerNewPromiseCapability(implicit context: Context)(
constructor: HeapObject, debugEvent: Object): PromiseCapability { constructor: HeapObject, debugEvent: Object): PromiseCapability {
const nativeContext = LoadNativeContext(context); const nativeContext = LoadNativeContext(context);
if (TaggedEqual(constructor, nativeContext[PROMISE_FUNCTION_INDEX])) { if (TaggedEqual(
constructor,
nativeContext[NativeContextSlot::PROMISE_FUNCTION_INDEX])) {
const promise = AllocateAndInitJSPromise(nativeContext); const promise = AllocateAndInitJSPromise(nativeContext);
const pair = const pair =
...@@ -337,9 +324,11 @@ namespace promise { ...@@ -337,9 +324,11 @@ namespace promise {
CreatePromiseCapabilitiesExecutorContext(nativeContext, capability); CreatePromiseCapabilitiesExecutorContext(nativeContext, capability);
const executorInfo = UnsafeCast<SharedFunctionInfo>( const executorInfo = UnsafeCast<SharedFunctionInfo>(
nativeContext[PROMISE_GET_CAPABILITIES_EXECUTOR_SHARED_FUN]); nativeContext[NativeContextSlot::
PROMISE_GET_CAPABILITIES_EXECUTOR_SHARED_FUN]);
const functionMap = UnsafeCast<Map>( const functionMap = UnsafeCast<Map>(
nativeContext[STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX]); nativeContext
[NativeContextSlot::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX]);
const executor = AllocateFunctionWithMapAndContext( const executor = AllocateFunctionWithMapAndContext(
functionMap, executorInfo, executorContext); functionMap, executorInfo, executorContext);
...@@ -349,7 +338,7 @@ namespace promise { ...@@ -349,7 +338,7 @@ namespace promise {
if (!TaggedIsCallable(capability.resolve) || if (!TaggedIsCallable(capability.resolve) ||
!TaggedIsCallable(capability.reject)) { !TaggedIsCallable(capability.reject)) {
ThrowTypeError(kPromiseNonCallable); ThrowTypeError(MessageTemplate::kPromiseNonCallable);
} }
return capability; return capability;
} }
...@@ -361,11 +350,11 @@ namespace promise { ...@@ -361,11 +350,11 @@ namespace promise {
maybeConstructor: Object, debugEvent: Object): PromiseCapability { maybeConstructor: Object, debugEvent: Object): PromiseCapability {
typeswitch (maybeConstructor) { typeswitch (maybeConstructor) {
case (Smi): { case (Smi): {
ThrowTypeError(kNotConstructor, maybeConstructor); ThrowTypeError(MessageTemplate::kNotConstructor, maybeConstructor);
} }
case (constructor: HeapObject): { case (constructor: HeapObject): {
if (!IsConstructor(constructor)) { if (!IsConstructor(constructor)) {
ThrowTypeError(kNotConstructor, maybeConstructor); ThrowTypeError(MessageTemplate::kNotConstructor, maybeConstructor);
} }
return InnerNewPromiseCapability(constructor, debugEvent); return InnerNewPromiseCapability(constructor, debugEvent);
} }
...@@ -436,7 +425,7 @@ namespace promise { ...@@ -436,7 +425,7 @@ namespace promise {
promise: JSPromise, onFulfilled: Callable|Undefined, promise: JSPromise, onFulfilled: Callable|Undefined,
onRejected: Callable|Undefined, onRejected: Callable|Undefined,
resultPromiseOrCapability: JSPromise|PromiseCapability|Undefined): void { resultPromiseOrCapability: JSPromise|PromiseCapability|Undefined): void {
if (promise.Status() == kPromisePending) { if (promise.Status() == PromiseState::kPending) {
// The {promise} is still in "Pending" state, so we just record a new // The {promise} is still in "Pending" state, so we just record a new
// PromiseReaction holding both the onFulfilled and onRejected callbacks. // PromiseReaction holding both the onFulfilled and onRejected callbacks.
// Once the {promise} is resolved we decide on the concrete handler to // Once the {promise} is resolved we decide on the concrete handler to
...@@ -449,13 +438,13 @@ namespace promise { ...@@ -449,13 +438,13 @@ namespace promise {
let map: Map; let map: Map;
let handler: HeapObject; let handler: HeapObject;
let handlerContext: Context; let handlerContext: Context;
if (promise.Status() == kPromiseFulfilled) { if (promise.Status() == PromiseState::kFulfilled) {
map = PromiseFulfillReactionJobTaskMapConstant(); map = PromiseFulfillReactionJobTaskMapConstant();
handler = onFulfilled; handler = onFulfilled;
handlerContext = ExtractHandlerContext(onFulfilled, onRejected); handlerContext = ExtractHandlerContext(onFulfilled, onRejected);
} else } else
deferred { deferred {
assert(promise.Status() == kPromiseRejected); assert(promise.Status() == PromiseState::kRejected);
map = PromiseRejectReactionJobTaskMapConstant(); map = PromiseRejectReactionJobTaskMapConstant();
handler = onRejected; handler = onRejected;
handlerContext = ExtractHandlerContext(onRejected, onFulfilled); handlerContext = ExtractHandlerContext(onRejected, onFulfilled);
...@@ -494,12 +483,12 @@ namespace promise { ...@@ -494,12 +483,12 @@ namespace promise {
// 1. Let C be the this value. // 1. Let C be the this value.
// 2. If Type(C) is not Object, throw a TypeError exception. // 2. If Type(C) is not Object, throw a TypeError exception.
const receiver = Cast<JSReceiver>(receiver) otherwise const receiver = Cast<JSReceiver>(receiver) otherwise
ThrowTypeError(kCalledOnNonObject, 'PromiseReject'); ThrowTypeError(MessageTemplate::kCalledOnNonObject, 'PromiseReject');
const promiseFun = context[PROMISE_FUNCTION_INDEX]; const promiseFun = context[NativeContextSlot::PROMISE_FUNCTION_INDEX];
if (promiseFun == receiver) { if (promiseFun == receiver) {
const promise = const promise =
AllocateAndSetJSPromise(context, kPromiseRejected, reason); AllocateAndSetJSPromise(context, PromiseState::kRejected, reason);
runtime::PromiseRejectEventFromStack(promise, reason); runtime::PromiseRejectEventFromStack(promise, reason);
return promise; return promise;
} else { } else {
......
...@@ -22,10 +22,6 @@ namespace promise { ...@@ -22,10 +22,6 @@ namespace promise {
extern runtime IncrementUseCounter(Context, Smi): void; extern runtime IncrementUseCounter(Context, Smi): void;
type UseCounterFeature extends int31 type UseCounterFeature extends int31
constexpr 'v8::Isolate::UseCounterFeature'; constexpr 'v8::Isolate::UseCounterFeature';
const kNotAPromise: constexpr MessageTemplate
generates 'MessageTemplate::kNotAPromise';
const kResolverNotAFunction: constexpr MessageTemplate
generates 'MessageTemplate::kResolverNotAFunction';
const kPromiseConstructorReturnedUndefined: constexpr UseCounterFeature const kPromiseConstructorReturnedUndefined: constexpr UseCounterFeature
generates 'v8::Isolate::kPromiseConstructorReturnedUndefined'; generates 'v8::Isolate::kPromiseConstructorReturnedUndefined';
...@@ -60,15 +56,16 @@ namespace promise { ...@@ -60,15 +56,16 @@ namespace promise {
newTarget: JSAny)(executor: JSAny): JSAny { newTarget: JSAny)(executor: JSAny): JSAny {
// 1. If NewTarget is undefined, throw a TypeError exception. // 1. If NewTarget is undefined, throw a TypeError exception.
if (newTarget == Undefined) { if (newTarget == Undefined) {
ThrowTypeError(kNotAPromise, newTarget); ThrowTypeError(MessageTemplate::kNotAPromise, newTarget);
} }
// 2. If IsCallable(executor) is false, throw a TypeError exception. // 2. If IsCallable(executor) is false, throw a TypeError exception.
if (!TaggedIsCallable(executor)) { if (!TaggedIsCallable(executor)) {
ThrowTypeError(kResolverNotAFunction, executor); ThrowTypeError(MessageTemplate::kResolverNotAFunction, executor);
} }
const promiseFun = UnsafeCast<JSFunction>(context[PROMISE_FUNCTION_INDEX]); const promiseFun = UnsafeCast<JSFunction>(
context[NativeContextSlot::PROMISE_FUNCTION_INDEX]);
// Silently fail if the stack looks fishy. // Silently fail if the stack looks fishy.
if (HasAccessCheckFailed(context, context, promiseFun, executor)) { if (HasAccessCheckFailed(context, context, promiseFun, executor)) {
......
...@@ -6,9 +6,6 @@ ...@@ -6,9 +6,6 @@
// https://tc39.es/ecma262/#sec-promise-jobs // https://tc39.es/ecma262/#sec-promise-jobs
namespace promise { namespace promise {
const PROMISE_THEN_INDEX: constexpr NativeContextSlot
generates 'Context::PROMISE_THEN_INDEX';
extern macro IsJSPromiseMap(Map): bool; extern macro IsJSPromiseMap(Map): bool;
// https://tc39.es/ecma262/#sec-promiseresolvethenablejob // https://tc39.es/ecma262/#sec-promiseresolvethenablejob
...@@ -25,7 +22,7 @@ namespace promise { ...@@ -25,7 +22,7 @@ namespace promise {
// 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 = nativeContext[PROMISE_THEN_INDEX]; const promiseThen = nativeContext[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() &&
......
...@@ -10,12 +10,6 @@ namespace runtime { ...@@ -10,12 +10,6 @@ namespace runtime {
} }
namespace promise { namespace promise {
const kCalledOnNonObject: constexpr MessageTemplate
generates 'MessageTemplate::kCalledOnNonObject';
const PROMISE_PROTOTYPE_INDEX: constexpr NativeContextSlot
generates 'Context::PROMISE_PROTOTYPE_INDEX';
extern macro ConstructorStringConstant(): String; extern macro ConstructorStringConstant(): String;
const kConstructorString: String = ConstructorStringConstant(); const kConstructorString: String = ConstructorStringConstant();
...@@ -26,7 +20,7 @@ namespace promise { ...@@ -26,7 +20,7 @@ namespace promise {
// 1. Let C be the this value. // 1. Let C be the this value.
// 2. If Type(C) is not Object, throw a TypeError exception. // 2. If Type(C) is not Object, throw a TypeError exception.
const receiver = Cast<JSReceiver>(receiver) otherwise const receiver = Cast<JSReceiver>(receiver) otherwise
ThrowTypeError(kCalledOnNonObject, 'PromiseResolve'); ThrowTypeError(MessageTemplate::kCalledOnNonObject, 'PromiseResolve');
// 3. Return ? PromiseResolve(C, x). // 3. Return ? PromiseResolve(C, x).
return PromiseResolve(receiver, value); return PromiseResolve(receiver, value);
...@@ -36,7 +30,7 @@ namespace promise { ...@@ -36,7 +30,7 @@ namespace promise {
PromiseResolve(implicit context: PromiseResolve(implicit context:
Context)(constructor: JSReceiver, value: JSAny): JSAny { Context)(constructor: JSReceiver, value: JSAny): JSAny {
const nativeContext = LoadNativeContext(context); const nativeContext = LoadNativeContext(context);
const promiseFun = nativeContext[PROMISE_FUNCTION_INDEX]; const promiseFun = nativeContext[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;
...@@ -45,7 +39,8 @@ namespace promise { ...@@ -45,7 +39,8 @@ namespace promise {
// is the (initial) Promise.prototype and the @@species protector is // is the (initial) Promise.prototype and the @@species protector is
// 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 = nativeContext[PROMISE_PROTOTYPE_INDEX]; const promisePrototype =
nativeContext[NativeContextSlot::PROMISE_PROTOTYPE_INDEX];
if (value.map.prototype != promisePrototype) { if (value.map.prototype != promisePrototype) {
goto SlowConstructor; goto SlowConstructor;
} }
...@@ -146,17 +141,19 @@ namespace promise { ...@@ -146,17 +141,19 @@ namespace promise {
// results from async generators. // results from async generators.
assert(IsJSReceiverMap(resolutionMap)); assert(IsJSReceiverMap(resolutionMap));
assert(!IsPromiseThenProtectorCellInvalid()); assert(!IsPromiseThenProtectorCellInvalid());
if (resolutionMap == nativeContext[ITERATOR_RESULT_MAP_INDEX]) { if (resolutionMap ==
nativeContext[NativeContextSlot::ITERATOR_RESULT_MAP_INDEX]) {
return FulfillPromise(promise, resolution); return FulfillPromise(promise, resolution);
} else { } else {
goto Slow; goto Slow;
} }
} }
const promisePrototype = nativeContext[PROMISE_PROTOTYPE_INDEX]; const promisePrototype =
nativeContext[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 = nativeContext[PROMISE_THEN_INDEX]; then = nativeContext[NativeContextSlot::PROMISE_THEN_INDEX];
goto Enqueue; goto Enqueue;
} }
goto Slow; goto Slow;
......
...@@ -29,10 +29,12 @@ namespace promise { ...@@ -29,10 +29,12 @@ namespace promise {
// 1. Let promise be the this value. // 1. Let promise be the this value.
// 2. If IsPromise(promise) is false, throw a TypeError exception. // 2. If IsPromise(promise) is false, throw a TypeError exception.
const promise = Cast<JSPromise>(receiver) otherwise ThrowTypeError( const promise = Cast<JSPromise>(receiver) otherwise ThrowTypeError(
kIncompatibleMethodReceiver, 'Promise.prototype.then', receiver); MessageTemplate::kIncompatibleMethodReceiver, 'Promise.prototype.then',
receiver);
// 3. Let C be ? SpeciesConstructor(promise, %Promise%). // 3. Let C be ? SpeciesConstructor(promise, %Promise%).
const promiseFun = UnsafeCast<JSFunction>(context[PROMISE_FUNCTION_INDEX]); const promiseFun = UnsafeCast<JSFunction>(
context[NativeContextSlot::PROMISE_FUNCTION_INDEX]);
// 4. Let resultCapability be ? NewPromiseCapability(C). // 4. Let resultCapability be ? NewPromiseCapability(C).
let resultPromiseOrCapability: JSPromise|PromiseCapability; let resultPromiseOrCapability: JSPromise|PromiseCapability;
......
...@@ -15,7 +15,7 @@ namespace proxy { ...@@ -15,7 +15,7 @@ namespace proxy {
try { try {
// 1. If NewTarget is undefined, throw a TypeError exception. // 1. If NewTarget is undefined, throw a TypeError exception.
if (newTarget == Undefined) { if (newTarget == Undefined) {
ThrowTypeError(kConstructorNotFunction, 'Proxy'); ThrowTypeError(MessageTemplate::kConstructorNotFunction, 'Proxy');
} }
// 2. Return ? ProxyCreate(target, handler). // 2. Return ? ProxyCreate(target, handler).
...@@ -51,10 +51,10 @@ namespace proxy { ...@@ -51,10 +51,10 @@ namespace proxy {
return AllocateProxy(targetJSReceiver, handlerJSReceiver); return AllocateProxy(targetJSReceiver, handlerJSReceiver);
} }
label ThrowProxyNonObject deferred { label ThrowProxyNonObject deferred {
ThrowTypeError(kProxyNonObject); ThrowTypeError(MessageTemplate::kProxyNonObject);
} }
label ThrowProxyHandlerOrTargetRevoked deferred { label ThrowProxyHandlerOrTargetRevoked deferred {
ThrowTypeError(kProxyHandlerOrTargetRevoked); ThrowTypeError(MessageTemplate::kProxyHandlerOrTargetRevoked);
} }
} }
} }
...@@ -41,8 +41,9 @@ namespace proxy { ...@@ -41,8 +41,9 @@ namespace proxy {
// 9. If booleanTrapResult is false, return false. // 9. If booleanTrapResult is false, return false.
if (!ToBoolean(trapResult)) { if (!ToBoolean(trapResult)) {
if (languageMode == SmiConstant(kStrict)) { if (languageMode == SmiConstant(LanguageMode::kStrict)) {
ThrowTypeError(kProxyTrapReturnedFalsishFor, kTrapName, name); ThrowTypeError(
MessageTemplate::kProxyTrapReturnedFalsishFor, kTrapName, name);
} }
return False; return False;
} }
...@@ -63,7 +64,7 @@ namespace proxy { ...@@ -63,7 +64,7 @@ namespace proxy {
return DeleteProperty(target, name, languageMode); return DeleteProperty(target, name, languageMode);
} }
label ThrowProxyHandlerRevoked deferred { label ThrowProxyHandlerRevoked deferred {
ThrowTypeError(kProxyRevoked, kTrapName); ThrowTypeError(MessageTemplate::kProxyRevoked, kTrapName);
} }
} }
} }
...@@ -27,7 +27,7 @@ namespace proxy { ...@@ -27,7 +27,7 @@ namespace proxy {
let handler: JSReceiver; let handler: JSReceiver;
typeswitch (proxy.handler) { typeswitch (proxy.handler) {
case (Null): { case (Null): {
ThrowTypeError(kProxyRevoked, 'get'); ThrowTypeError(MessageTemplate::kProxyRevoked, 'get');
} }
case (h: JSReceiver): { case (h: JSReceiver): {
handler = h; handler = h;
......
...@@ -54,17 +54,17 @@ namespace proxy { ...@@ -54,17 +54,17 @@ namespace proxy {
if (SameValue(targetProto, handlerProto)) { if (SameValue(targetProto, handlerProto)) {
return handlerProto; return handlerProto;
} }
ThrowTypeError(kProxyGetPrototypeOfNonExtensible); ThrowTypeError(MessageTemplate::kProxyGetPrototypeOfNonExtensible);
} }
label TrapUndefined(target: JSAny) { label TrapUndefined(target: JSAny) {
// 6.a. Return ? target.[[GetPrototypeOf]](). // 6.a. Return ? target.[[GetPrototypeOf]]().
return object::ObjectGetPrototypeOfImpl(target); return object::ObjectGetPrototypeOfImpl(target);
} }
label ThrowProxyHandlerRevoked deferred { label ThrowProxyHandlerRevoked deferred {
ThrowTypeError(kProxyRevoked, kTrapName); ThrowTypeError(MessageTemplate::kProxyRevoked, kTrapName);
} }
label ThrowProxyGetPrototypeOfInvalid deferred { label ThrowProxyGetPrototypeOfInvalid deferred {
ThrowTypeError(kProxyGetPrototypeOfInvalid); ThrowTypeError(MessageTemplate::kProxyGetPrototypeOfInvalid);
} }
} }
} }
...@@ -51,7 +51,7 @@ namespace proxy { ...@@ -51,7 +51,7 @@ namespace proxy {
tail HasProperty(target, name); tail HasProperty(target, name);
} }
label ThrowProxyHandlerRevoked deferred { label ThrowProxyHandlerRevoked deferred {
ThrowTypeError(kProxyRevoked, 'has'); ThrowTypeError(MessageTemplate::kProxyRevoked, 'has');
} }
} }
} }
...@@ -40,7 +40,7 @@ namespace proxy { ...@@ -40,7 +40,7 @@ namespace proxy {
// TypeError exception. // TypeError exception.
if (trapResult != targetResult) { if (trapResult != targetResult) {
ThrowTypeError( ThrowTypeError(
kProxyIsExtensibleInconsistent, MessageTemplate::kProxyIsExtensibleInconsistent,
SelectBooleanConstant(targetResult)); SelectBooleanConstant(targetResult));
} }
// 10. Return booleanTrapResult. // 10. Return booleanTrapResult.
...@@ -51,7 +51,7 @@ namespace proxy { ...@@ -51,7 +51,7 @@ namespace proxy {
return object::ObjectIsExtensibleImpl(target); return object::ObjectIsExtensibleImpl(target);
} }
label ThrowProxyHandlerRevoked deferred { label ThrowProxyHandlerRevoked deferred {
ThrowTypeError(kProxyRevoked, kTrapName); ThrowTypeError(MessageTemplate::kProxyRevoked, kTrapName);
} }
} }
} }
...@@ -40,11 +40,11 @@ namespace proxy { ...@@ -40,11 +40,11 @@ namespace proxy {
const extensibleTarget: JSAny = object::ObjectIsExtensibleImpl(target); const extensibleTarget: JSAny = object::ObjectIsExtensibleImpl(target);
assert(extensibleTarget == True || extensibleTarget == False); assert(extensibleTarget == True || extensibleTarget == False);
if (extensibleTarget == True) { if (extensibleTarget == True) {
ThrowTypeError(kProxyPreventExtensionsExtensible); ThrowTypeError(MessageTemplate::kProxyPreventExtensionsExtensible);
} }
} else { } else {
if (doThrow == True) { if (doThrow == True) {
ThrowTypeError(kProxyTrapReturnedFalsish, kTrapName); ThrowTypeError(MessageTemplate::kProxyTrapReturnedFalsish, kTrapName);
} }
return False; return False;
} }
...@@ -60,7 +60,7 @@ namespace proxy { ...@@ -60,7 +60,7 @@ namespace proxy {
return object::ObjectPreventExtensionsDontThrow(target); return object::ObjectPreventExtensionsDontThrow(target);
} }
label ThrowProxyHandlerRevoked deferred { label ThrowProxyHandlerRevoked deferred {
ThrowTypeError(kProxyRevoked, kTrapName); ThrowTypeError(MessageTemplate::kProxyRevoked, kTrapName);
} }
} }
} // namespace proxy } // namespace proxy
...@@ -43,10 +43,11 @@ namespace proxy { ...@@ -43,10 +43,11 @@ namespace proxy {
return NewJSProxyRevocableResult(proxy, revoke); return NewJSProxyRevocableResult(proxy, revoke);
} }
label ThrowProxyNonObject deferred { label ThrowProxyNonObject deferred {
ThrowTypeError(kProxyNonObject, 'Proxy.revocable'); ThrowTypeError(MessageTemplate::kProxyNonObject, 'Proxy.revocable');
} }
label ThrowProxyHandlerOrTargetRevoked deferred { label ThrowProxyHandlerOrTargetRevoked deferred {
ThrowTypeError(kProxyHandlerOrTargetRevoked, 'Proxy.revocable'); ThrowTypeError(
MessageTemplate::kProxyHandlerOrTargetRevoked, 'Proxy.revocable');
} }
} }
} }
...@@ -28,7 +28,7 @@ namespace proxy { ...@@ -28,7 +28,7 @@ namespace proxy {
let key: PropertyKey; let key: PropertyKey;
typeswitch (name) { typeswitch (name) {
case (PrivateSymbol): { case (PrivateSymbol): {
CallThrowTypeErrorIfStrict(kProxyPrivate); CallThrowTypeErrorIfStrict(MessageTemplate::kProxyPrivate);
return Undefined; return Undefined;
} }
case (name: PropertyKey): { case (name: PropertyKey): {
...@@ -73,7 +73,8 @@ namespace proxy { ...@@ -73,7 +73,8 @@ namespace proxy {
return value; return value;
} }
ThrowTypeErrorIfStrict( ThrowTypeErrorIfStrict(
SmiConstant(kProxyTrapReturnedFalsishFor), 'set', name); SmiConstant(MessageTemplate::kProxyTrapReturnedFalsishFor), 'set',
name);
return value; return value;
} }
label TrapUndefined(target: Object) { label TrapUndefined(target: Object) {
...@@ -82,7 +83,7 @@ namespace proxy { ...@@ -82,7 +83,7 @@ namespace proxy {
return value; return value;
} }
label ThrowProxyHandlerRevoked deferred { label ThrowProxyHandlerRevoked deferred {
ThrowTypeError(kProxyRevoked, 'set'); ThrowTypeError(MessageTemplate::kProxyRevoked, 'set');
} }
} }
} }
...@@ -39,7 +39,8 @@ namespace proxy { ...@@ -39,7 +39,8 @@ namespace proxy {
// 9. If booleanTrapResult is false, return false. // 9. If booleanTrapResult is false, return false.
if (!ToBoolean(trapResult)) { if (!ToBoolean(trapResult)) {
if (doThrow == True) { if (doThrow == True) {
ThrowTypeError(kProxyTrapReturnedFalsishFor, kTrapName); ThrowTypeError(
MessageTemplate::kProxyTrapReturnedFalsishFor, kTrapName);
} }
return False; return False;
} }
...@@ -61,7 +62,7 @@ namespace proxy { ...@@ -61,7 +62,7 @@ namespace proxy {
if (SameValue(proto, targetProto)) { if (SameValue(proto, targetProto)) {
return True; return True;
} }
ThrowTypeError(kProxySetPrototypeOfNonExtensible); ThrowTypeError(MessageTemplate::kProxySetPrototypeOfNonExtensible);
} }
label TrapUndefined(target: JSAny, proto: JSReceiver|Null) { label TrapUndefined(target: JSAny, proto: JSReceiver|Null) {
// 7.a. Return ? target.[[SetPrototypeOf]](). // 7.a. Return ? target.[[SetPrototypeOf]]().
...@@ -71,7 +72,7 @@ namespace proxy { ...@@ -71,7 +72,7 @@ namespace proxy {
return object::ObjectSetPrototypeOfDontThrow(target, proto); return object::ObjectSetPrototypeOfDontThrow(target, proto);
} }
label ThrowProxyHandlerRevoked deferred { label ThrowProxyHandlerRevoked deferred {
ThrowTypeError(kProxyRevoked, kTrapName); ThrowTypeError(MessageTemplate::kProxyRevoked, kTrapName);
} }
} }
} }
...@@ -25,31 +25,6 @@ namespace proxy { ...@@ -25,31 +25,6 @@ namespace proxy {
extern transitioning macro ProxiesCodeStubAssembler::CheckHasTrapResult( extern transitioning macro ProxiesCodeStubAssembler::CheckHasTrapResult(
implicit context: Context)(JSReceiver, JSProxy, Name); implicit context: Context)(JSReceiver, JSProxy, Name);
const kProxyNonObject: constexpr MessageTemplate
generates 'MessageTemplate::kProxyNonObject';
const kProxyHandlerOrTargetRevoked: constexpr MessageTemplate
generates 'MessageTemplate::kProxyHandlerOrTargetRevoked';
const kProxyRevoked: constexpr MessageTemplate
generates 'MessageTemplate::kProxyRevoked';
const kProxyTrapReturnedFalsishFor: constexpr MessageTemplate
generates 'MessageTemplate::kProxyTrapReturnedFalsishFor';
const kProxyPrivate: constexpr MessageTemplate
generates 'MessageTemplate::kProxyPrivate';
const kProxyIsExtensibleInconsistent: constexpr MessageTemplate
generates 'MessageTemplate::kProxyIsExtensibleInconsistent';
const kProxyPreventExtensionsExtensible: constexpr MessageTemplate
generates 'MessageTemplate::kProxyPreventExtensionsExtensible';
const kProxyTrapReturnedFalsish: constexpr MessageTemplate
generates 'MessageTemplate::kProxyTrapReturnedFalsish';
const kProxyGetPrototypeOfInvalid: constexpr MessageTemplate
generates 'MessageTemplate::kProxyGetPrototypeOfInvalid';
const kProxyGetPrototypeOfNonExtensible: constexpr MessageTemplate
generates 'MessageTemplate::kProxyGetPrototypeOfNonExtensible';
const kProxySetPrototypeOfNonExtensible: constexpr MessageTemplate
generates 'MessageTemplate::kProxySetPrototypeOfNonExtensible';
const kProxyDeletePropertyNonExtensible: constexpr MessageTemplate
generates 'MessageTemplate::kProxyDeletePropertyNonExtensible';
const kProxyGet: constexpr int31 const kProxyGet: constexpr int31
generates 'JSProxy::AccessKind::kGet'; generates 'JSProxy::AccessKind::kGet';
const kProxySet: constexpr int31 const kProxySet: constexpr int31
......
...@@ -3,16 +3,13 @@ ...@@ -3,16 +3,13 @@
// found in the LICENSE file. // found in the LICENSE file.
namespace reflect { namespace reflect {
const kCalledOnNonObject: constexpr MessageTemplate
generates 'MessageTemplate::kCalledOnNonObject';
// ES6 section 26.1.10 Reflect.isExtensible // ES6 section 26.1.10 Reflect.isExtensible
transitioning javascript builtin transitioning javascript builtin
ReflectIsExtensible(js-implicit context: NativeContext)(object: JSAny): ReflectIsExtensible(js-implicit context: NativeContext)(object: JSAny):
JSAny { JSAny {
const objectJSReceiver = Cast<JSReceiver>(object) const objectJSReceiver = Cast<JSReceiver>(object)
otherwise ThrowTypeError(kCalledOnNonObject, 'Reflect.isExtensible'); otherwise ThrowTypeError(
MessageTemplate::kCalledOnNonObject, 'Reflect.isExtensible');
return object::ObjectIsExtensibleImpl(objectJSReceiver); return object::ObjectIsExtensibleImpl(objectJSReceiver);
} }
...@@ -21,7 +18,8 @@ namespace reflect { ...@@ -21,7 +18,8 @@ namespace reflect {
ReflectPreventExtensions(js-implicit context: NativeContext)(object: JSAny): ReflectPreventExtensions(js-implicit context: NativeContext)(object: JSAny):
JSAny { JSAny {
const objectJSReceiver = Cast<JSReceiver>(object) const objectJSReceiver = Cast<JSReceiver>(object)
otherwise ThrowTypeError(kCalledOnNonObject, 'Reflect.preventExtensions'); otherwise ThrowTypeError(
MessageTemplate::kCalledOnNonObject, 'Reflect.preventExtensions');
return object::ObjectPreventExtensionsDontThrow(objectJSReceiver); return object::ObjectPreventExtensionsDontThrow(objectJSReceiver);
} }
...@@ -30,7 +28,8 @@ namespace reflect { ...@@ -30,7 +28,8 @@ namespace reflect {
ReflectGetPrototypeOf(js-implicit context: NativeContext)(object: JSAny): ReflectGetPrototypeOf(js-implicit context: NativeContext)(object: JSAny):
JSAny { JSAny {
const objectJSReceiver = Cast<JSReceiver>(object) const objectJSReceiver = Cast<JSReceiver>(object)
otherwise ThrowTypeError(kCalledOnNonObject, 'Reflect.getPrototypeOf'); otherwise ThrowTypeError(
MessageTemplate::kCalledOnNonObject, 'Reflect.getPrototypeOf');
return object::JSReceiverGetPrototypeOf(objectJSReceiver); return object::JSReceiverGetPrototypeOf(objectJSReceiver);
} }
...@@ -38,13 +37,14 @@ namespace reflect { ...@@ -38,13 +37,14 @@ namespace reflect {
transitioning javascript builtin ReflectSetPrototypeOf( transitioning javascript builtin ReflectSetPrototypeOf(
js-implicit context: NativeContext)(object: JSAny, proto: JSAny): JSAny { js-implicit context: NativeContext)(object: JSAny, proto: JSAny): JSAny {
const objectJSReceiver = Cast<JSReceiver>(object) const objectJSReceiver = Cast<JSReceiver>(object)
otherwise ThrowTypeError(kCalledOnNonObject, 'Reflect.setPrototypeOf'); otherwise ThrowTypeError(
MessageTemplate::kCalledOnNonObject, 'Reflect.setPrototypeOf');
typeswitch (proto) { typeswitch (proto) {
case (proto: JSReceiver|Null): { case (proto: JSReceiver|Null): {
return object::ObjectSetPrototypeOfDontThrow(objectJSReceiver, proto); return object::ObjectSetPrototypeOfDontThrow(objectJSReceiver, proto);
} }
case (JSAny): { case (JSAny): {
ThrowTypeError(kProtoObjectOrNull, proto); ThrowTypeError(MessageTemplate::kProtoObjectOrNull, proto);
} }
} }
} }
...@@ -64,7 +64,8 @@ namespace reflect { ...@@ -64,7 +64,8 @@ namespace reflect {
const length = arguments.length; const length = arguments.length;
const object: JSAny = length > 0 ? arguments[0] : Undefined; const object: JSAny = length > 0 ? arguments[0] : Undefined;
const objectJSReceiver = Cast<JSReceiver>(object) const objectJSReceiver = Cast<JSReceiver>(object)
otherwise ThrowTypeError(kCalledOnNonObject, 'Reflect.get'); otherwise ThrowTypeError(
MessageTemplate::kCalledOnNonObject, 'Reflect.get');
const propertyKey: JSAny = length > 1 ? arguments[1] : Undefined; const propertyKey: JSAny = length > 1 ? arguments[1] : Undefined;
const name: AnyName = ToName(propertyKey); const name: AnyName = ToName(propertyKey);
const receiver: JSAny = length > 2 ? arguments[2] : objectJSReceiver; const receiver: JSAny = length > 2 ? arguments[2] : objectJSReceiver;
...@@ -76,8 +77,9 @@ namespace reflect { ...@@ -76,8 +77,9 @@ namespace reflect {
transitioning javascript builtin ReflectDeleteProperty( transitioning javascript builtin ReflectDeleteProperty(
js-implicit context: NativeContext)(object: JSAny, key: JSAny): JSAny { js-implicit context: NativeContext)(object: JSAny, key: JSAny): JSAny {
const objectJSReceiver = Cast<JSReceiver>(object) const objectJSReceiver = Cast<JSReceiver>(object)
otherwise ThrowTypeError(kCalledOnNonObject, 'Reflect.deleteProperty'); otherwise ThrowTypeError(
return DeleteProperty(objectJSReceiver, key, kSloppy); MessageTemplate::kCalledOnNonObject, 'Reflect.deleteProperty');
return DeleteProperty(objectJSReceiver, key, LanguageMode::kSloppy);
} }
// ES section #sec-reflect.has // ES section #sec-reflect.has
...@@ -85,7 +87,8 @@ namespace reflect { ...@@ -85,7 +87,8 @@ namespace reflect {
ReflectHas(js-implicit context: NativeContext)(object: JSAny, key: JSAny): ReflectHas(js-implicit context: NativeContext)(object: JSAny, key: JSAny):
JSAny { JSAny {
const objectJSReceiver = Cast<JSReceiver>(object) const objectJSReceiver = Cast<JSReceiver>(object)
otherwise ThrowTypeError(kCalledOnNonObject, 'Reflect.has'); otherwise ThrowTypeError(
MessageTemplate::kCalledOnNonObject, 'Reflect.has');
return HasProperty(objectJSReceiver, key); return HasProperty(objectJSReceiver, key);
} }
} // namespace reflect } // namespace reflect
...@@ -34,7 +34,8 @@ namespace regexp { ...@@ -34,7 +34,8 @@ namespace regexp {
receiver: JSAny)(string: JSAny): JSAny { receiver: JSAny)(string: JSAny): JSAny {
// Ensure {receiver} is a JSRegExp. // Ensure {receiver} is a JSRegExp.
const receiver = Cast<JSRegExp>(receiver) otherwise ThrowTypeError( const receiver = Cast<JSRegExp>(receiver) otherwise ThrowTypeError(
kIncompatibleMethodReceiver, 'RegExp.prototype.exec', receiver); MessageTemplate::kIncompatibleMethodReceiver, 'RegExp.prototype.exec',
receiver);
const string = ToString_Inline(string); const string = ToString_Inline(string);
return IsFastRegExpNoPrototype(receiver) ? return IsFastRegExpNoPrototype(receiver) ?
......
...@@ -16,7 +16,8 @@ namespace regexp { ...@@ -16,7 +16,8 @@ namespace regexp {
// 1. Let R be the this value. // 1. Let R be the this value.
// 2. If Type(R) is not Object, throw a TypeError exception. // 2. If Type(R) is not Object, throw a TypeError exception.
ThrowIfNotJSReceiver( ThrowIfNotJSReceiver(
receiver, kIncompatibleMethodReceiver, 'RegExp.prototype.@@matchAll'); receiver, MessageTemplate::kIncompatibleMethodReceiver,
'RegExp.prototype.@@matchAll');
const receiver = UnsafeCast<JSReceiver>(receiver); const receiver = UnsafeCast<JSReceiver>(receiver);
// 3. Let S be ? ToString(O). // 3. Let S be ? ToString(O).
...@@ -49,11 +50,11 @@ namespace regexp { ...@@ -49,11 +50,11 @@ namespace regexp {
// 9. If flags contains "g", let global be true. // 9. If flags contains "g", let global be true.
// 10. Else, let global be false. // 10. Else, let global be false.
global = FastFlagGetter(matcherRegExp, kGlobal); global = FastFlagGetter(matcherRegExp, Flag::kGlobal);
// 11. If flags contains "u", let fullUnicode be true. // 11. If flags contains "u", let fullUnicode be true.
// 12. Else, let fullUnicode be false. // 12. Else, let fullUnicode be false.
unicode = FastFlagGetter(matcherRegExp, kUnicode); unicode = FastFlagGetter(matcherRegExp, Flag::kUnicode);
} }
case (Object): { case (Object): {
// 4. Let C be ? SpeciesConstructor(R, %RegExp%). // 4. Let C be ? SpeciesConstructor(R, %RegExp%).
...@@ -140,7 +141,8 @@ namespace regexp { ...@@ -140,7 +141,8 @@ namespace regexp {
const methodName: constexpr string = const methodName: constexpr string =
'%RegExpStringIterator%.prototype.next'; '%RegExpStringIterator%.prototype.next';
const receiver = Cast<JSRegExpStringIterator>(receiver) otherwise const receiver = Cast<JSRegExpStringIterator>(receiver) otherwise
ThrowTypeError(kIncompatibleMethodReceiver, methodName, receiver); ThrowTypeError(
MessageTemplate::kIncompatibleMethodReceiver, methodName, receiver);
try { try {
// 4. If O.[[Done]] is true, then // 4. If O.[[Done]] is true, then
......
...@@ -22,7 +22,7 @@ namespace regexp { ...@@ -22,7 +22,7 @@ namespace regexp {
assert(Is<FastJSRegExp>(regexp)); assert(Is<FastJSRegExp>(regexp));
} }
const isGlobal: bool = FlagGetter(regexp, kGlobal, isFastPath); const isGlobal: bool = FlagGetter(regexp, Flag::kGlobal, isFastPath);
if (!isGlobal) { if (!isGlobal) {
return isFastPath ? RegExpPrototypeExecBodyFast(regexp, string) : return isFastPath ? RegExpPrototypeExecBodyFast(regexp, string) :
...@@ -30,7 +30,7 @@ namespace regexp { ...@@ -30,7 +30,7 @@ namespace regexp {
} }
assert(isGlobal); assert(isGlobal);
const isUnicode: bool = FlagGetter(regexp, kUnicode, isFastPath); const isUnicode: bool = FlagGetter(regexp, Flag::kUnicode, isFastPath);
StoreLastIndex(regexp, 0, isFastPath); StoreLastIndex(regexp, 0, isFastPath);
...@@ -141,7 +141,8 @@ namespace regexp { ...@@ -141,7 +141,8 @@ namespace regexp {
js-implicit context: NativeContext, js-implicit context: NativeContext,
receiver: JSAny)(string: JSAny): JSAny { receiver: JSAny)(string: JSAny): JSAny {
ThrowIfNotJSReceiver( ThrowIfNotJSReceiver(
receiver, kIncompatibleMethodReceiver, 'RegExp.prototype.@@match'); receiver, MessageTemplate::kIncompatibleMethodReceiver,
'RegExp.prototype.@@match');
const receiver = UnsafeCast<JSReceiver>(receiver); const receiver = UnsafeCast<JSReceiver>(receiver);
const string: String = ToString_Inline(string); const string: String = ToString_Inline(string);
......
...@@ -89,7 +89,7 @@ namespace regexp { ...@@ -89,7 +89,7 @@ namespace regexp {
const result: Null|JSArray = RegExpExecMultiple( const result: Null|JSArray = RegExpExecMultiple(
regexp, string, GetRegExpLastMatchInfo(), regexp, string, GetRegExpLastMatchInfo(),
AllocateJSArray( AllocateJSArray(
PACKED_ELEMENTS, GetFastPackedElementsJSArrayMap(), ElementsKind::PACKED_ELEMENTS, GetFastPackedElementsJSArrayMap(),
kInitialCapacity, kInitialLength)); kInitialCapacity, kInitialLength));
regexp.lastIndex = 0; regexp.lastIndex = 0;
...@@ -243,7 +243,8 @@ namespace regexp { ...@@ -243,7 +243,8 @@ namespace regexp {
// Let rx be the this value. // Let rx be the this value.
// If Type(rx) is not Object, throw a TypeError exception. // If Type(rx) is not Object, throw a TypeError exception.
const rx = Cast<JSReceiver>(receiver) const rx = Cast<JSReceiver>(receiver)
otherwise ThrowTypeError(kIncompatibleMethodReceiver, methodName); otherwise ThrowTypeError(
MessageTemplate::kIncompatibleMethodReceiver, methodName);
// Let S be ? ToString(string). // Let S be ? ToString(string).
const s = ToString_Inline(string); const s = ToString_Inline(string);
......
...@@ -93,7 +93,8 @@ namespace regexp { ...@@ -93,7 +93,8 @@ namespace regexp {
js-implicit context: NativeContext, js-implicit context: NativeContext,
receiver: JSAny)(string: JSAny): JSAny { receiver: JSAny)(string: JSAny): JSAny {
ThrowIfNotJSReceiver( ThrowIfNotJSReceiver(
receiver, kIncompatibleMethodReceiver, 'RegExp.prototype.@@search'); receiver, MessageTemplate::kIncompatibleMethodReceiver,
'RegExp.prototype.@@search');
const receiver = UnsafeCast<JSReceiver>(receiver); const receiver = UnsafeCast<JSReceiver>(receiver);
const string: String = ToString_Inline(string); const string: String = ToString_Inline(string);
......
...@@ -19,7 +19,7 @@ namespace regexp { ...@@ -19,7 +19,7 @@ namespace regexp {
} }
if (!IsReceiverInitialRegExpPrototype(receiver)) { if (!IsReceiverInitialRegExpPrototype(receiver)) {
const methodName: constexpr string = 'RegExp.prototype.source'; const methodName: constexpr string = 'RegExp.prototype.source';
ThrowTypeError(kRegExpNonRegExp, methodName); ThrowTypeError(MessageTemplate::kRegExpNonRegExp, methodName);
} }
IncrementUseCounter(context, SmiConstant(kRegExpPrototypeSourceGetter)); IncrementUseCounter(context, SmiConstant(kRegExpPrototypeSourceGetter));
return '(?:)'; return '(?:)';
......
...@@ -43,7 +43,7 @@ namespace regexp { ...@@ -43,7 +43,7 @@ namespace regexp {
// the given regexp is non-sticky to avoid invalid results. See // the given regexp is non-sticky to avoid invalid results. See
// crbug.com/v8/6706. // crbug.com/v8/6706.
if (FastFlagGetter(regexp, kSticky)) { if (FastFlagGetter(regexp, Flag::kSticky)) {
return runtime::RegExpSplit(regexp, string, sanitizedLimit); return runtime::RegExpSplit(regexp, string, sanitizedLimit);
} }
...@@ -57,7 +57,8 @@ namespace regexp { ...@@ -57,7 +57,8 @@ namespace regexp {
js-implicit context: NativeContext, js-implicit context: NativeContext,
receiver: JSAny)(...arguments): JSAny { receiver: JSAny)(...arguments): JSAny {
ThrowIfNotJSReceiver( ThrowIfNotJSReceiver(
receiver, kIncompatibleMethodReceiver, 'RegExp.prototype.@@split'); receiver, MessageTemplate::kIncompatibleMethodReceiver,
'RegExp.prototype.@@split');
const receiver = UnsafeCast<JSReceiver>(receiver); const receiver = UnsafeCast<JSReceiver>(receiver);
const string: String = ToString_Inline(arguments[0]); const string: String = ToString_Inline(arguments[0]);
const limit = arguments[1]; const limit = arguments[1];
......
...@@ -13,7 +13,8 @@ namespace regexp { ...@@ -13,7 +13,8 @@ namespace regexp {
receiver: JSAny)(string: JSAny): JSAny { receiver: JSAny)(string: JSAny): JSAny {
const methodName: constexpr string = 'RegExp.prototype.test'; const methodName: constexpr string = 'RegExp.prototype.test';
const receiver = Cast<JSReceiver>(receiver) const receiver = Cast<JSReceiver>(receiver)
otherwise ThrowTypeError(kIncompatibleMethodReceiver, methodName); otherwise ThrowTypeError(
MessageTemplate::kIncompatibleMethodReceiver, methodName);
const str: String = ToString_Inline(string); const str: String = ToString_Inline(string);
if (IsFastRegExpPermissive(receiver)) { if (IsFastRegExpPermissive(receiver)) {
RegExpPrototypeExecBodyWithoutResultFast( RegExpPrototypeExecBodyWithoutResultFast(
......
...@@ -22,9 +22,6 @@ namespace regexp { ...@@ -22,9 +22,6 @@ namespace regexp {
BranchIfFastRegExp_Permissive(o) otherwise return true, return false; BranchIfFastRegExp_Permissive(o) otherwise return true, return false;
} }
const kInvalidRegExpExecResult: constexpr MessageTemplate
generates 'MessageTemplate::kInvalidRegExpExecResult';
// ES#sec-regexpexec Runtime Semantics: RegExpExec ( R, S ) // ES#sec-regexpexec Runtime Semantics: RegExpExec ( R, S )
@export @export
transitioning macro RegExpExec(implicit context: Context)( transitioning macro RegExpExec(implicit context: Context)(
...@@ -39,13 +36,15 @@ namespace regexp { ...@@ -39,13 +36,15 @@ namespace regexp {
case (execCallable: Callable): { case (execCallable: Callable): {
const result = Call(context, execCallable, receiver, string); const result = Call(context, execCallable, receiver, string);
if (result != Null) { if (result != Null) {
ThrowIfNotJSReceiver(result, kInvalidRegExpExecResult, ''); ThrowIfNotJSReceiver(
result, MessageTemplate::kInvalidRegExpExecResult, '');
} }
return result; return result;
} }
case (Object): { case (Object): {
const regexp = Cast<JSRegExp>(receiver) otherwise ThrowTypeError( const regexp = Cast<JSRegExp>(receiver) otherwise ThrowTypeError(
kIncompatibleMethodReceiver, 'RegExp.prototype.exec', receiver); MessageTemplate::kIncompatibleMethodReceiver,
'RegExp.prototype.exec', receiver);
return RegExpPrototypeExecSlow(regexp, string); return RegExpPrototypeExecSlow(regexp, string);
} }
} }
...@@ -147,7 +146,8 @@ namespace regexp { ...@@ -147,7 +146,8 @@ namespace regexp {
regexp = UnsafeCast<JSRegExp>(receiver); regexp = UnsafeCast<JSRegExp>(receiver);
} else { } else {
regexp = Cast<JSRegExp>(receiver) otherwise ThrowTypeError( regexp = Cast<JSRegExp>(receiver) otherwise ThrowTypeError(
kIncompatibleMethodReceiver, 'RegExp.prototype.exec', receiver); MessageTemplate::kIncompatibleMethodReceiver, 'RegExp.prototype.exec',
receiver);
} }
const lastIndex = LoadLastIndexAsLength(regexp, isFastPath); const lastIndex = LoadLastIndexAsLength(regexp, isFastPath);
const matchIndices: RegExpMatchInfo = RegExpPrototypeExecBodyWithoutResult( const matchIndices: RegExpMatchInfo = RegExpPrototypeExecBodyWithoutResult(
...@@ -158,7 +158,8 @@ namespace regexp { ...@@ -158,7 +158,8 @@ namespace regexp {
macro LoadRegExpFunction(implicit context: Context)( macro LoadRegExpFunction(implicit context: Context)(
nativeContext: NativeContext): JSFunction { nativeContext: NativeContext): JSFunction {
return UnsafeCast<JSFunction>(nativeContext[REGEXP_FUNCTION_INDEX]); return UnsafeCast<JSFunction>(
nativeContext[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
...@@ -179,19 +180,15 @@ namespace regexp { ...@@ -179,19 +180,15 @@ namespace regexp {
return TaggedEqual(receiver, initialPrototype); return TaggedEqual(receiver, initialPrototype);
} }
type Flag constexpr 'JSRegExp::Flag'; extern enum Flag constexpr 'JSRegExp::Flag' {
const kGlobal: constexpr Flag kGlobal,
generates 'JSRegExp::kGlobal'; kIgnoreCase,
const kIgnoreCase: constexpr Flag kMultiline,
generates 'JSRegExp::kIgnoreCase'; kSticky,
const kMultiline: constexpr Flag kUnicode,
generates 'JSRegExp::kMultiline'; kDotAll,
const kDotAll: constexpr Flag kInvalid
generates 'JSRegExp::kDotAll'; }
const kSticky: constexpr Flag
generates 'JSRegExp::kSticky';
const kUnicode: constexpr Flag
generates 'JSRegExp::kUnicode';
const kRegExpPrototypeOldFlagGetter: constexpr int31 const kRegExpPrototypeOldFlagGetter: constexpr int31
generates 'v8::Isolate::kRegExpPrototypeOldFlagGetter'; generates 'v8::Isolate::kRegExpPrototypeOldFlagGetter';
...@@ -202,8 +199,6 @@ namespace regexp { ...@@ -202,8 +199,6 @@ namespace regexp {
extern macro RegExpBuiltinsAssembler::FastFlagGetter( extern macro RegExpBuiltinsAssembler::FastFlagGetter(
JSRegExp, constexpr Flag): bool; JSRegExp, constexpr Flag): bool;
const kRegExpNonRegExp: constexpr MessageTemplate
generates 'MessageTemplate::kRegExpNonRegExp';
extern runtime IncrementUseCounter(Context, Smi): void; extern runtime IncrementUseCounter(Context, Smi): void;
macro FlagGetter(implicit context: Context)( macro FlagGetter(implicit context: Context)(
...@@ -217,7 +212,7 @@ namespace regexp { ...@@ -217,7 +212,7 @@ namespace regexp {
} }
} }
if (!IsReceiverInitialRegExpPrototype(receiver)) { if (!IsReceiverInitialRegExpPrototype(receiver)) {
ThrowTypeError(kRegExpNonRegExp, methodName); ThrowTypeError(MessageTemplate::kRegExpNonRegExp, methodName);
} }
if constexpr (counter != -1) { if constexpr (counter != -1) {
IncrementUseCounter(context, SmiConstant(counter)); IncrementUseCounter(context, SmiConstant(counter));
...@@ -230,7 +225,7 @@ namespace regexp { ...@@ -230,7 +225,7 @@ namespace regexp {
transitioning javascript builtin RegExpPrototypeGlobalGetter( transitioning javascript builtin RegExpPrototypeGlobalGetter(
js-implicit context: NativeContext, receiver: JSAny)(): JSAny { js-implicit context: NativeContext, receiver: JSAny)(): JSAny {
return FlagGetter( return FlagGetter(
receiver, kGlobal, kRegExpPrototypeOldFlagGetter, receiver, Flag::kGlobal, kRegExpPrototypeOldFlagGetter,
'RegExp.prototype.global'); 'RegExp.prototype.global');
} }
...@@ -239,7 +234,7 @@ namespace regexp { ...@@ -239,7 +234,7 @@ namespace regexp {
transitioning javascript builtin RegExpPrototypeIgnoreCaseGetter( transitioning javascript builtin RegExpPrototypeIgnoreCaseGetter(
js-implicit context: NativeContext, receiver: JSAny)(): JSAny { js-implicit context: NativeContext, receiver: JSAny)(): JSAny {
return FlagGetter( return FlagGetter(
receiver, kIgnoreCase, kRegExpPrototypeOldFlagGetter, receiver, Flag::kIgnoreCase, kRegExpPrototypeOldFlagGetter,
'RegExp.prototype.ignoreCase'); 'RegExp.prototype.ignoreCase');
} }
...@@ -248,7 +243,7 @@ namespace regexp { ...@@ -248,7 +243,7 @@ namespace regexp {
transitioning javascript builtin RegExpPrototypeMultilineGetter( transitioning javascript builtin RegExpPrototypeMultilineGetter(
js-implicit context: NativeContext, receiver: JSAny)(): JSAny { js-implicit context: NativeContext, receiver: JSAny)(): JSAny {
return FlagGetter( return FlagGetter(
receiver, kMultiline, kRegExpPrototypeOldFlagGetter, receiver, Flag::kMultiline, kRegExpPrototypeOldFlagGetter,
'RegExp.prototype.multiline'); 'RegExp.prototype.multiline');
} }
...@@ -256,7 +251,8 @@ namespace regexp { ...@@ -256,7 +251,8 @@ namespace regexp {
transitioning javascript builtin RegExpPrototypeDotAllGetter( transitioning javascript builtin RegExpPrototypeDotAllGetter(
js-implicit context: NativeContext, receiver: JSAny)(): JSAny { js-implicit context: NativeContext, receiver: JSAny)(): JSAny {
const kNoCounter: constexpr int31 = -1; const kNoCounter: constexpr int31 = -1;
return FlagGetter(receiver, kDotAll, kNoCounter, 'RegExp.prototype.dotAll'); return FlagGetter(
receiver, Flag::kDotAll, kNoCounter, 'RegExp.prototype.dotAll');
} }
// ES6 21.2.5.12. // ES6 21.2.5.12.
...@@ -264,7 +260,7 @@ namespace regexp { ...@@ -264,7 +260,7 @@ namespace regexp {
transitioning javascript builtin RegExpPrototypeStickyGetter( transitioning javascript builtin RegExpPrototypeStickyGetter(
js-implicit context: NativeContext, receiver: JSAny)(): JSAny { js-implicit context: NativeContext, receiver: JSAny)(): JSAny {
return FlagGetter( return FlagGetter(
receiver, kSticky, kRegExpPrototypeStickyGetter, receiver, Flag::kSticky, kRegExpPrototypeStickyGetter,
'RegExp.prototype.sticky'); 'RegExp.prototype.sticky');
} }
...@@ -273,7 +269,7 @@ namespace regexp { ...@@ -273,7 +269,7 @@ namespace regexp {
transitioning javascript builtin RegExpPrototypeUnicodeGetter( transitioning javascript builtin RegExpPrototypeUnicodeGetter(
js-implicit context: NativeContext, receiver: JSAny)(): JSAny { js-implicit context: NativeContext, receiver: JSAny)(): JSAny {
return FlagGetter( return FlagGetter(
receiver, kUnicode, kRegExpPrototypeUnicodeGetter, receiver, Flag::kUnicode, kRegExpPrototypeUnicodeGetter,
'RegExp.prototype.unicode'); 'RegExp.prototype.unicode');
} }
...@@ -291,14 +287,12 @@ namespace regexp { ...@@ -291,14 +287,12 @@ namespace regexp {
return FlagsGetter(receiver, false); return FlagsGetter(receiver, false);
} }
const kRegExpNonObject: constexpr MessageTemplate
generates 'MessageTemplate::kRegExpNonObject';
// ES #sec-get-regexp.prototype.flags // ES #sec-get-regexp.prototype.flags
// TFJ(RegExpPrototypeFlagsGetter, 0, kReceiver) \ // TFJ(RegExpPrototypeFlagsGetter, 0, kReceiver) \
transitioning javascript builtin RegExpPrototypeFlagsGetter( transitioning javascript builtin RegExpPrototypeFlagsGetter(
js-implicit context: NativeContext, receiver: JSAny)(): String { js-implicit context: NativeContext, receiver: JSAny)(): String {
ThrowIfNotJSReceiver(receiver, kRegExpNonObject, 'RegExp.prototype.flags'); ThrowIfNotJSReceiver(
receiver, MessageTemplate::kRegExpNonObject, 'RegExp.prototype.flags');
// The check is strict because the following code relies on individual flag // The check is strict because the following code relies on individual flag
// getters on the regexp prototype (e.g.: global, sticky, ...). We don't // getters on the regexp prototype (e.g.: global, sticky, ...). We don't
......
...@@ -39,7 +39,7 @@ namespace string { ...@@ -39,7 +39,7 @@ namespace string {
// 3. Let isRegExp be ? IsRegExp(searchString). // 3. Let isRegExp be ? IsRegExp(searchString).
// 4. If isRegExp is true, throw a TypeError exception. // 4. If isRegExp is true, throw a TypeError exception.
if (regexp::IsRegExp(searchString)) { if (regexp::IsRegExp(searchString)) {
ThrowTypeError(kFirstArgumentNotRegExp, kBuiltinName); ThrowTypeError(MessageTemplate::kFirstArgumentNotRegExp, kBuiltinName);
} }
// 5. Let searchStr be ? ToString(searchString). // 5. Let searchStr be ? ToString(searchString).
......
...@@ -28,8 +28,8 @@ namespace string { ...@@ -28,8 +28,8 @@ namespace string {
transitioning javascript builtin StringIteratorPrototypeNext( transitioning javascript builtin StringIteratorPrototypeNext(
js-implicit context: NativeContext, receiver: JSAny)(): JSObject { js-implicit context: NativeContext, receiver: JSAny)(): JSObject {
const iterator = Cast<JSStringIterator>(receiver) otherwise ThrowTypeError( const iterator = Cast<JSStringIterator>(receiver) otherwise ThrowTypeError(
kIncompatibleMethodReceiver, 'String Iterator.prototype.next', MessageTemplate::kIncompatibleMethodReceiver,
receiver); 'String Iterator.prototype.next', receiver);
const string = iterator.string; const string = iterator.string;
const position: intptr = SmiUntag(iterator.index); const position: intptr = SmiUntag(iterator.index);
const length: intptr = string.length_intptr; const length: intptr = string.length_intptr;
...@@ -37,7 +37,7 @@ namespace string { ...@@ -37,7 +37,7 @@ namespace string {
return AllocateJSIteratorResult(Undefined, True); return AllocateJSIteratorResult(Undefined, True);
} }
// Move to next codepoint. // Move to next codepoint.
const encoding = UTF16; const encoding = UnicodeEncoding::UTF16;
const ch = string::LoadSurrogatePairAt(string, length, position, encoding); const ch = string::LoadSurrogatePairAt(string, length, position, encoding);
const value: String = string::StringFromSingleUTF16EncodedCodePoint(ch); const value: String = string::StringFromSingleUTF16EncodedCodePoint(ch);
iterator.index = SmiTag(position + value.length_intptr); iterator.index = SmiTag(position + value.length_intptr);
......
...@@ -69,7 +69,7 @@ namespace string { ...@@ -69,7 +69,7 @@ namespace string {
return kEmptyString; return kEmptyString;
} }
label InvalidCount deferred { label InvalidCount deferred {
ThrowRangeError(kInvalidCountValue, count); ThrowRangeError(MessageTemplate::kInvalidCountValue, count);
} }
label InvalidStringLength deferred { label InvalidStringLength deferred {
ThrowInvalidStringLength(context); ThrowInvalidStringLength(context);
......
...@@ -5,10 +5,6 @@ ...@@ -5,10 +5,6 @@
#include 'src/builtins/builtins-string-gen.h' #include 'src/builtins/builtins-string-gen.h'
namespace string { namespace string {
const kRegExpGlobalInvokedOnNonGlobal: constexpr MessageTemplate
generates 'MessageTemplate::kRegExpGlobalInvokedOnNonGlobal';
extern macro ReplaceSymbolConstant(): Symbol; extern macro ReplaceSymbolConstant(): Symbol;
extern macro StringBuiltinsAssembler::GetSubstitution( extern macro StringBuiltinsAssembler::GetSubstitution(
...@@ -88,7 +84,8 @@ namespace string { ...@@ -88,7 +84,8 @@ namespace string {
} }
if (shouldThrow) { if (shouldThrow) {
ThrowTypeError( ThrowTypeError(
kRegExpGlobalInvokedOnNonGlobal, 'String.prototype.replaceAll'); MessageTemplate::kRegExpGlobalInvokedOnNonGlobal,
'String.prototype.replaceAll');
} }
} }
......
...@@ -20,7 +20,7 @@ namespace string { ...@@ -20,7 +20,7 @@ namespace string {
// 3. Let isRegExp be ? IsRegExp(searchString). // 3. Let isRegExp be ? IsRegExp(searchString).
// 4. If isRegExp is true, throw a TypeError exception. // 4. If isRegExp is true, throw a TypeError exception.
if (regexp::IsRegExp(searchString)) { if (regexp::IsRegExp(searchString)) {
ThrowTypeError(kFirstArgumentNotRegExp, kBuiltinName); ThrowTypeError(MessageTemplate::kFirstArgumentNotRegExp, kBuiltinName);
} }
// 5. Let searchStr be ? ToString(searchString). // 5. Let searchStr be ? ToString(searchString).
......
...@@ -8,7 +8,8 @@ namespace symbol { ...@@ -8,7 +8,8 @@ namespace symbol {
transitioning macro ThisSymbolValue(implicit context: Context)( transitioning macro ThisSymbolValue(implicit context: Context)(
receiver: JSAny, method: constexpr string): Symbol { receiver: JSAny, method: constexpr string): Symbol {
return UnsafeCast<Symbol>(ToThisValue(receiver, kSymbol, method)); return UnsafeCast<Symbol>(
ToThisValue(receiver, PrimitiveType::kSymbol, method));
} }
// ES #sec-symbol.prototype.description // ES #sec-symbol.prototype.description
......
...@@ -130,7 +130,7 @@ namespace typed_array { ...@@ -130,7 +130,7 @@ namespace typed_array {
otherwise RangeError; otherwise RangeError;
} }
label RangeError deferred { label RangeError deferred {
ThrowRangeError(kInvalidTypedArrayLength, lengthObj); ThrowRangeError(MessageTemplate::kInvalidTypedArrayLength, lengthObj);
} }
} }
...@@ -151,7 +151,7 @@ namespace typed_array { ...@@ -151,7 +151,7 @@ namespace typed_array {
Cast<JSTypedArray>(arrayLike) otherwise IfSlow; Cast<JSTypedArray>(arrayLike) otherwise IfSlow;
if (IsDetachedBuffer(src.buffer)) { if (IsDetachedBuffer(src.buffer)) {
ThrowTypeError(kDetachedOperation, 'Construct'); ThrowTypeError(MessageTemplate::kDetachedOperation, 'Construct');
} else if (src.elements_kind != elementsInfo.kind) { } else if (src.elements_kind != elementsInfo.kind) {
goto IfSlow; goto IfSlow;
...@@ -172,7 +172,8 @@ namespace typed_array { ...@@ -172,7 +172,8 @@ namespace typed_array {
return typedArray; return typedArray;
} }
label RangeError deferred { label RangeError deferred {
ThrowRangeError(kInvalidTypedArrayLength, Convert<Number>(length)); ThrowRangeError(
MessageTemplate::kInvalidTypedArrayLength, Convert<Number>(length));
} }
} }
...@@ -231,7 +232,7 @@ namespace typed_array { ...@@ -231,7 +232,7 @@ namespace typed_array {
// 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. // 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
if (IsDetachedBuffer(buffer)) { if (IsDetachedBuffer(buffer)) {
ThrowTypeError(kDetachedOperation, 'Construct'); ThrowTypeError(MessageTemplate::kDetachedOperation, 'Construct');
} }
// 10. Let bufferByteLength be buffer.[[ArrayBufferByteLength]]. // 10. Let bufferByteLength be buffer.[[ArrayBufferByteLength]].
...@@ -276,10 +277,10 @@ namespace typed_array { ...@@ -276,10 +277,10 @@ namespace typed_array {
ThrowInvalidTypedArrayAlignment(map, problemString); ThrowInvalidTypedArrayAlignment(map, problemString);
} }
label IfInvalidLength deferred { label IfInvalidLength deferred {
ThrowRangeError(kInvalidTypedArrayLength, length); ThrowRangeError(MessageTemplate::kInvalidTypedArrayLength, length);
} }
label IfInvalidOffset deferred { label IfInvalidOffset deferred {
ThrowRangeError(kInvalidOffset, byteOffset); ThrowRangeError(MessageTemplate::kInvalidOffset, byteOffset);
} }
} }
...@@ -300,14 +301,14 @@ namespace typed_array { ...@@ -300,14 +301,14 @@ namespace typed_array {
ValidateTypedArray(context, newTypedArrayObj, methodName); ValidateTypedArray(context, newTypedArrayObj, methodName);
if (IsDetachedBuffer(newTypedArray.buffer)) deferred { if (IsDetachedBuffer(newTypedArray.buffer)) deferred {
ThrowTypeError(kDetachedOperation, methodName); ThrowTypeError(MessageTemplate::kDetachedOperation, methodName);
} }
// 3. If argumentList is a List of a single Number, then // 3. If argumentList is a List of a single Number, then
// a. If newTypedArray.[[ArrayLength]] < argumentList[0], throw a // a. If newTypedArray.[[ArrayLength]] < argumentList[0], throw a
// TypeError exception. // TypeError exception.
if (newTypedArray.length < Convert<uintptr>(length)) deferred { if (newTypedArray.length < Convert<uintptr>(length)) deferred {
ThrowTypeError(kTypedArrayTooShort); ThrowTypeError(MessageTemplate::kTypedArrayTooShort);
} }
// 4. Return newTypedArray. // 4. Return newTypedArray.
...@@ -336,10 +337,10 @@ namespace typed_array { ...@@ -336,10 +337,10 @@ namespace typed_array {
goto IfConstructByArrayLike(obj, length, GetArrayBufferFunction()); goto IfConstructByArrayLike(obj, length, GetArrayBufferFunction());
} }
label IfInvalidLength(length: Number) { label IfInvalidLength(length: Number) {
ThrowRangeError(kInvalidTypedArrayLength, length); ThrowRangeError(MessageTemplate::kInvalidTypedArrayLength, length);
} }
label IfIteratorNotCallable(_value: JSAny) deferred { label IfIteratorNotCallable(_value: JSAny) deferred {
ThrowTypeError(kIteratorSymbolNonCallable); ThrowTypeError(MessageTemplate::kIteratorSymbolNonCallable);
} }
} }
...@@ -437,7 +438,7 @@ namespace typed_array { ...@@ -437,7 +438,7 @@ namespace typed_array {
methodName, numArgs, exemplar, Convert<Number>(length), Undefined, methodName, numArgs, exemplar, Convert<Number>(length), Undefined,
Undefined); Undefined);
if (typedArray.length < length) deferred { if (typedArray.length < length) deferred {
ThrowTypeError(kTypedArrayTooShort); ThrowTypeError(MessageTemplate::kTypedArrayTooShort);
} }
return typedArray; return typedArray;
} }
......
...@@ -44,13 +44,13 @@ namespace typed_array { ...@@ -44,13 +44,13 @@ namespace typed_array {
return EveryAllElements(uarray, callbackfn, thisArg); return EveryAllElements(uarray, callbackfn, thisArg);
} }
label NotCallable deferred { label NotCallable deferred {
ThrowTypeError(kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} }
label NotTypedArray deferred { label NotTypedArray deferred {
ThrowTypeError(kNotTypedArray, kBuiltinNameEvery); ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameEvery);
} }
label IsDetached deferred { label IsDetached deferred {
ThrowTypeError(kDetachedOperation, kBuiltinNameEvery); ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameEvery);
} }
} }
} }
...@@ -15,7 +15,8 @@ namespace typed_array { ...@@ -15,7 +15,8 @@ namespace typed_array {
// 1. Let O be the this value. // 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O). // 2. Perform ? ValidateTypedArray(O).
const array: JSTypedArray = Cast<JSTypedArray>(receiver) const array: JSTypedArray = Cast<JSTypedArray>(receiver)
otherwise ThrowTypeError(kNotTypedArray, kBuiltinNameFilter); otherwise ThrowTypeError(
MessageTemplate::kNotTypedArray, kBuiltinNameFilter);
const src = typed_array::EnsureAttached(array) otherwise IsDetached; const src = typed_array::EnsureAttached(array) otherwise IsDetached;
// 3. Let len be O.[[ArrayLength]]. // 3. Let len be O.[[ArrayLength]].
...@@ -23,7 +24,8 @@ namespace typed_array { ...@@ -23,7 +24,8 @@ namespace typed_array {
// 4. If IsCallable(callbackfn) is false, throw a TypeError exception. // 4. If IsCallable(callbackfn) is false, throw a TypeError exception.
const callbackfn = Cast<Callable>(arguments[0]) const callbackfn = Cast<Callable>(arguments[0])
otherwise ThrowTypeError(kCalledNonCallable, arguments[0]); otherwise ThrowTypeError(
MessageTemplate::kCalledNonCallable, arguments[0]);
// 5. If thisArg is present, let T be thisArg; else let T be undefined. // 5. If thisArg is present, let T be thisArg; else let T be undefined.
const thisArg: JSAny = arguments[1]; const thisArg: JSAny = arguments[1];
...@@ -79,7 +81,7 @@ namespace typed_array { ...@@ -79,7 +81,7 @@ namespace typed_array {
return typedArray; return typedArray;
} }
label IsDetached deferred { label IsDetached deferred {
ThrowTypeError(kDetachedOperation, kBuiltinNameFilter); ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameFilter);
} }
} }
} }
...@@ -44,13 +44,13 @@ namespace typed_array { ...@@ -44,13 +44,13 @@ namespace typed_array {
return FindAllElements(uarray, callbackfn, thisArg); return FindAllElements(uarray, callbackfn, thisArg);
} }
label NotCallable deferred { label NotCallable deferred {
ThrowTypeError(kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} }
label NotTypedArray deferred { label NotTypedArray deferred {
ThrowTypeError(kNotTypedArray, kBuiltinNameFind); ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameFind);
} }
label IsDetached deferred { label IsDetached deferred {
ThrowTypeError(kDetachedOperation, kBuiltinNameFind); ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameFind);
} }
} }
} }
...@@ -47,13 +47,14 @@ namespace typed_array { ...@@ -47,13 +47,14 @@ namespace typed_array {
return FindIndexAllElements(uarray, callbackfn, thisArg); return FindIndexAllElements(uarray, callbackfn, thisArg);
} }
label NotCallable deferred { label NotCallable deferred {
ThrowTypeError(kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} }
label NotTypedArray deferred { label NotTypedArray deferred {
ThrowTypeError(kNotTypedArray, kBuiltinNameFindIndex); ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameFindIndex);
} }
label IsDetached deferred { label IsDetached deferred {
ThrowTypeError(kDetachedOperation, kBuiltinNameFindIndex); ThrowTypeError(
MessageTemplate::kDetachedOperation, kBuiltinNameFindIndex);
} }
} }
} }
...@@ -44,13 +44,13 @@ namespace typed_array { ...@@ -44,13 +44,13 @@ namespace typed_array {
return ForEachAllElements(uarray, callbackfn, thisArg); return ForEachAllElements(uarray, callbackfn, thisArg);
} }
label NotCallable deferred { label NotCallable deferred {
ThrowTypeError(kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} }
label NotTypedArray deferred { label NotTypedArray deferred {
ThrowTypeError(kNotTypedArray, kBuiltinNameForEach); ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameForEach);
} }
label IsDetached deferred { label IsDetached deferred {
ThrowTypeError(kDetachedOperation, kBuiltinNameForEach); ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameForEach);
} }
} }
} }
...@@ -33,7 +33,7 @@ namespace typed_array { ...@@ -33,7 +33,7 @@ namespace typed_array {
const mapping: bool = arguments.length > 1; const mapping: bool = arguments.length > 1;
const mapfnObj: JSAny = mapping ? arguments[1] : Undefined; const mapfnObj: JSAny = mapping ? arguments[1] : Undefined;
if (mapping && !TaggedIsCallable(mapfnObj)) deferred { if (mapping && !TaggedIsCallable(mapfnObj)) deferred {
ThrowTypeError(kCalledNonCallable, mapfnObj); ThrowTypeError(MessageTemplate::kCalledNonCallable, mapfnObj);
} }
// 5. If thisArg is present, let T be thisArg; else let T be undefined. // 5. If thisArg is present, let T be thisArg; else let T be undefined.
...@@ -127,11 +127,11 @@ namespace typed_array { ...@@ -127,11 +127,11 @@ namespace typed_array {
finalSource = arrayLike; finalSource = arrayLike;
} }
label IfInvalidLength deferred { label IfInvalidLength deferred {
ThrowRangeError(kInvalidTypedArrayLength, length); ThrowRangeError(MessageTemplate::kInvalidTypedArrayLength, length);
} }
} }
label IteratorNotCallable(_value: JSAny) deferred { label IteratorNotCallable(_value: JSAny) deferred {
ThrowTypeError(kIteratorSymbolNonCallable); ThrowTypeError(MessageTemplate::kIteratorSymbolNonCallable);
} }
const finalLengthNum = Convert<Number>(finalLength); const finalLengthNum = Convert<Number>(finalLength);
...@@ -185,10 +185,10 @@ namespace typed_array { ...@@ -185,10 +185,10 @@ namespace typed_array {
return targetObj; return targetObj;
} }
label NotConstructor deferred { label NotConstructor deferred {
ThrowTypeError(kNotConstructor, receiver); ThrowTypeError(MessageTemplate::kNotConstructor, receiver);
} }
label IfDetached deferred { label IfDetached deferred {
ThrowTypeError(kDetachedOperation, kBuiltinNameFrom); ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameFrom);
} }
} }
} }
...@@ -47,10 +47,10 @@ namespace typed_array { ...@@ -47,10 +47,10 @@ namespace typed_array {
return newObj; return newObj;
} }
label NotConstructor deferred { label NotConstructor deferred {
ThrowTypeError(kNotConstructor, receiver); ThrowTypeError(MessageTemplate::kNotConstructor, receiver);
} }
label IfDetached deferred { label IfDetached deferred {
ThrowTypeError(kDetachedOperation, kBuiltinNameOf); ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameOf);
} }
} }
} }
...@@ -32,7 +32,7 @@ namespace typed_array { ...@@ -32,7 +32,7 @@ namespace typed_array {
} }
typeswitch (accumulator) { typeswitch (accumulator) {
case (TheHole): { case (TheHole): {
ThrowTypeError(kReduceNoInitial, kBuiltinNameReduce); ThrowTypeError(MessageTemplate::kReduceNoInitial, kBuiltinNameReduce);
} }
case (accumulator: JSAny): { case (accumulator: JSAny): {
return accumulator; return accumulator;
...@@ -57,13 +57,13 @@ namespace typed_array { ...@@ -57,13 +57,13 @@ namespace typed_array {
return ReduceAllElements(uarray, callbackfn, initialValue); return ReduceAllElements(uarray, callbackfn, initialValue);
} }
label NotCallable deferred { label NotCallable deferred {
ThrowTypeError(kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} }
label NotTypedArray deferred { label NotTypedArray deferred {
ThrowTypeError(kNotTypedArray, kBuiltinNameReduce); ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameReduce);
} }
label IsDetached deferred { label IsDetached deferred {
ThrowTypeError(kDetachedOperation, kBuiltinNameReduce); ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameReduce);
} }
} }
} }
...@@ -33,7 +33,8 @@ namespace typed_array { ...@@ -33,7 +33,8 @@ namespace typed_array {
} }
typeswitch (accumulator) { typeswitch (accumulator) {
case (TheHole): { case (TheHole): {
ThrowTypeError(kReduceNoInitial, kBuiltinNameReduceRight); ThrowTypeError(
MessageTemplate::kReduceNoInitial, kBuiltinNameReduceRight);
} }
case (accumulator: JSAny): { case (accumulator: JSAny): {
return accumulator; return accumulator;
...@@ -59,13 +60,14 @@ namespace typed_array { ...@@ -59,13 +60,14 @@ namespace typed_array {
return ReduceRightAllElements(uarray, callbackfn, initialValue); return ReduceRightAllElements(uarray, callbackfn, initialValue);
} }
label NotCallable deferred { label NotCallable deferred {
ThrowTypeError(kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} }
label NotTypedArray deferred { label NotTypedArray deferred {
ThrowTypeError(kNotTypedArray, kBuiltinNameReduceRight); ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameReduceRight);
} }
label IsDetached deferred { label IsDetached deferred {
ThrowTypeError(kDetachedOperation, kBuiltinNameReduceRight); ThrowTypeError(
MessageTemplate::kDetachedOperation, kBuiltinNameReduceRight);
} }
} }
} }
...@@ -44,7 +44,7 @@ namespace typed_array { ...@@ -44,7 +44,7 @@ namespace typed_array {
target = Cast<JSTypedArray>(receiver) otherwise NotTypedArray; target = Cast<JSTypedArray>(receiver) otherwise NotTypedArray;
} }
label NotTypedArray deferred { label NotTypedArray deferred {
ThrowTypeError(kNotTypedArray, kBuiltinNameSet); ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameSet);
} }
try { try {
...@@ -104,10 +104,10 @@ namespace typed_array { ...@@ -104,10 +104,10 @@ namespace typed_array {
} }
} }
label OffsetOutOfBounds deferred { label OffsetOutOfBounds deferred {
ThrowRangeError(kTypedArraySetOffsetOutOfBounds); ThrowRangeError(MessageTemplate::kTypedArraySetOffsetOutOfBounds);
} }
label IsDetached deferred { label IsDetached deferred {
ThrowTypeError(kDetachedOperation, kBuiltinNameSet); ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameSet);
} }
} }
...@@ -127,7 +127,7 @@ namespace typed_array { ...@@ -127,7 +127,7 @@ namespace typed_array {
// For number as a first argument, throw TypeError instead of silently // For number as a first argument, throw TypeError instead of silently
// ignoring the call, so that users know they did something wrong. // ignoring the call, so that users know they did something wrong.
// (Consistent with Firefox and Blink/WebKit) // (Consistent with Firefox and Blink/WebKit)
ThrowTypeError(kInvalidArgument); ThrowTypeError(MessageTemplate::kInvalidArgument);
} }
label NotNumber { label NotNumber {
// Proceed to step 14. // Proceed to step 14.
...@@ -174,9 +174,11 @@ namespace typed_array { ...@@ -174,9 +174,11 @@ namespace typed_array {
// PACKED_SMI_ELEMENTS, HOLEY_SMI_ELEMENTS, PACKED_DOUBLE_ELEMENTS, // PACKED_SMI_ELEMENTS, HOLEY_SMI_ELEMENTS, PACKED_DOUBLE_ELEMENTS,
// HOLEY_DOUBLE_ELEMENTS. // HOLEY_DOUBLE_ELEMENTS.
if (IsElementsKindInRange( if (IsElementsKindInRange(
srcKind, PACKED_SMI_ELEMENTS, HOLEY_SMI_ELEMENTS) || srcKind, ElementsKind::PACKED_SMI_ELEMENTS,
ElementsKind::HOLEY_SMI_ELEMENTS) ||
IsElementsKindInRange( IsElementsKindInRange(
srcKind, PACKED_DOUBLE_ELEMENTS, HOLEY_DOUBLE_ELEMENTS)) { srcKind, ElementsKind::PACKED_DOUBLE_ELEMENTS,
ElementsKind::HOLEY_DOUBLE_ELEMENTS)) {
const utarget = const utarget =
typed_array::EnsureAttached(target) otherwise IfDetached; typed_array::EnsureAttached(target) otherwise IfDetached;
CallCCopyFastNumberJSArrayElementsToTypedArray( CallCCopyFastNumberJSArrayElementsToTypedArray(
...@@ -295,7 +297,7 @@ namespace typed_array { ...@@ -295,7 +297,7 @@ namespace typed_array {
if (IsBigInt64ElementsKind(srcKind) != if (IsBigInt64ElementsKind(srcKind) !=
IsBigInt64ElementsKind(targetElementsInfo.kind)) IsBigInt64ElementsKind(targetElementsInfo.kind))
deferred { deferred {
ThrowTypeError(kBigIntMixedTypes); ThrowTypeError(MessageTemplate::kBigIntMixedTypes);
} }
// All the obvervable side effects are executed, so there's nothing else // All the obvervable side effects are executed, so there's nothing else
......
...@@ -44,7 +44,7 @@ namespace typed_array { ...@@ -44,7 +44,7 @@ namespace typed_array {
if (typed_array::IsBigInt64ElementsKind(src.elements_kind) != if (typed_array::IsBigInt64ElementsKind(src.elements_kind) !=
typed_array::IsBigInt64ElementsKind(dest.elements_kind)) typed_array::IsBigInt64ElementsKind(dest.elements_kind))
deferred { deferred {
ThrowTypeError(kBigIntMixedTypes); ThrowTypeError(MessageTemplate::kBigIntMixedTypes);
} }
CallCCopyTypedArrayElementsSlice(src, dest, k, final); CallCCopyTypedArrayElementsSlice(src, dest, k, final);
...@@ -94,7 +94,7 @@ namespace typed_array { ...@@ -94,7 +94,7 @@ namespace typed_array {
FastCopy(srcAttached, dest, k, count) otherwise IfSlow; FastCopy(srcAttached, dest, k, count) otherwise IfSlow;
} }
label IfDetached deferred { label IfDetached deferred {
ThrowTypeError(kDetachedOperation, kBuiltinNameSlice); ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameSlice);
} }
label IfSlow deferred { label IfSlow deferred {
SlowCopy(src, dest, k, final); SlowCopy(src, dest, k, final);
......
...@@ -44,13 +44,13 @@ namespace typed_array { ...@@ -44,13 +44,13 @@ namespace typed_array {
return SomeAllElements(uarray, callbackfn, thisArg); return SomeAllElements(uarray, callbackfn, thisArg);
} }
label NotCallable deferred { label NotCallable deferred {
ThrowTypeError(kCalledNonCallable, arguments[0]); ThrowTypeError(MessageTemplate::kCalledNonCallable, arguments[0]);
} }
label NotTypedArray deferred { label NotTypedArray deferred {
ThrowTypeError(kNotTypedArray, kBuiltinNameSome); ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameSome);
} }
label IsDetached deferred { label IsDetached deferred {
ThrowTypeError(kDetachedOperation, kBuiltinNameSome); ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameSome);
} }
} }
} }
...@@ -18,7 +18,7 @@ namespace typed_array { ...@@ -18,7 +18,7 @@ namespace typed_array {
// b. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. // b. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
if (IsDetachedBuffer(array.buffer)) { if (IsDetachedBuffer(array.buffer)) {
ThrowTypeError(kDetachedOperation, kBuiltinNameSort); ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameSort);
} }
// c. If v is NaN, return +0. // c. If v is NaN, return +0.
...@@ -93,7 +93,7 @@ namespace typed_array { ...@@ -93,7 +93,7 @@ namespace typed_array {
// throw a TypeError exception. // throw a TypeError exception.
const comparefnObj: JSAny = arguments.length > 0 ? arguments[0] : Undefined; const comparefnObj: JSAny = arguments.length > 0 ? arguments[0] : Undefined;
if (comparefnObj != Undefined && !TaggedIsCallable(comparefnObj)) { if (comparefnObj != Undefined && !TaggedIsCallable(comparefnObj)) {
ThrowTypeError(kBadSortComparisonFunction, comparefnObj); ThrowTypeError(MessageTemplate::kBadSortComparisonFunction, comparefnObj);
} }
// 2. Let obj be the this value. // 2. Let obj be the this value.
......
...@@ -13,7 +13,8 @@ namespace typed_array { ...@@ -13,7 +13,8 @@ namespace typed_array {
// 3. If O does not have a [[TypedArrayName]] internal slot, throw a // 3. If O does not have a [[TypedArrayName]] internal slot, throw a
// TypeError exception. // TypeError exception.
const source = Cast<JSTypedArray>(receiver) const source = Cast<JSTypedArray>(receiver)
otherwise ThrowTypeError(kIncompatibleMethodReceiver, methodName); otherwise ThrowTypeError(
MessageTemplate::kIncompatibleMethodReceiver, methodName);
// 5. Let buffer be O.[[ViewedArrayBuffer]]. // 5. Let buffer be O.[[ViewedArrayBuffer]].
const buffer = typed_array::GetBuffer(source); const buffer = typed_array::GetBuffer(source);
...@@ -51,7 +52,7 @@ namespace typed_array { ...@@ -51,7 +52,7 @@ namespace typed_array {
// 15. Let beginByteOffset be srcByteOffset + beginIndex × elementSize. // 15. Let beginByteOffset be srcByteOffset + beginIndex × elementSize.
const beginByteOffset = const beginByteOffset =
srcByteOffset + elementsInfo.CalculateByteLength(begin) srcByteOffset + elementsInfo.CalculateByteLength(begin)
otherwise ThrowRangeError(kInvalidArrayBufferLength); otherwise ThrowRangeError(MessageTemplate::kInvalidArrayBufferLength);
// 16. Let argumentsList be « buffer, beginByteOffset, newLength ». // 16. Let argumentsList be « buffer, beginByteOffset, newLength ».
// 17. Return ? TypedArraySpeciesCreate(O, argumentsList). // 17. Return ? TypedArraySpeciesCreate(O, argumentsList).
......
...@@ -128,30 +128,31 @@ namespace typed_array { ...@@ -128,30 +128,31 @@ namespace typed_array {
} }
macro GetTypedArrayAccessor(elementsKind: ElementsKind): TypedArrayAccessor { macro GetTypedArrayAccessor(elementsKind: ElementsKind): TypedArrayAccessor {
if (IsElementsKindGreaterThan(elementsKind, UINT32_ELEMENTS)) { if (IsElementsKindGreaterThan(
if (elementsKind == INT32_ELEMENTS) { elementsKind, ElementsKind::UINT32_ELEMENTS)) {
if (elementsKind == ElementsKind::INT32_ELEMENTS) {
return GetTypedArrayAccessor<Int32Elements>(); return GetTypedArrayAccessor<Int32Elements>();
} else if (elementsKind == FLOAT32_ELEMENTS) { } else if (elementsKind == ElementsKind::FLOAT32_ELEMENTS) {
return GetTypedArrayAccessor<Float32Elements>(); return GetTypedArrayAccessor<Float32Elements>();
} else if (elementsKind == FLOAT64_ELEMENTS) { } else if (elementsKind == ElementsKind::FLOAT64_ELEMENTS) {
return GetTypedArrayAccessor<Float64Elements>(); return GetTypedArrayAccessor<Float64Elements>();
} else if (elementsKind == UINT8_CLAMPED_ELEMENTS) { } else if (elementsKind == ElementsKind::UINT8_CLAMPED_ELEMENTS) {
return GetTypedArrayAccessor<Uint8ClampedElements>(); return GetTypedArrayAccessor<Uint8ClampedElements>();
} else if (elementsKind == BIGUINT64_ELEMENTS) { } else if (elementsKind == ElementsKind::BIGUINT64_ELEMENTS) {
return GetTypedArrayAccessor<BigUint64Elements>(); return GetTypedArrayAccessor<BigUint64Elements>();
} else if (elementsKind == BIGINT64_ELEMENTS) { } else if (elementsKind == ElementsKind::BIGINT64_ELEMENTS) {
return GetTypedArrayAccessor<BigInt64Elements>(); return GetTypedArrayAccessor<BigInt64Elements>();
} }
} else { } else {
if (elementsKind == UINT8_ELEMENTS) { if (elementsKind == ElementsKind::UINT8_ELEMENTS) {
return GetTypedArrayAccessor<Uint8Elements>(); return GetTypedArrayAccessor<Uint8Elements>();
} else if (elementsKind == INT8_ELEMENTS) { } else if (elementsKind == ElementsKind::INT8_ELEMENTS) {
return GetTypedArrayAccessor<Int8Elements>(); return GetTypedArrayAccessor<Int8Elements>();
} else if (elementsKind == UINT16_ELEMENTS) { } else if (elementsKind == ElementsKind::UINT16_ELEMENTS) {
return GetTypedArrayAccessor<Uint16Elements>(); return GetTypedArrayAccessor<Uint16Elements>();
} else if (elementsKind == INT16_ELEMENTS) { } else if (elementsKind == ElementsKind::INT16_ELEMENTS) {
return GetTypedArrayAccessor<Int16Elements>(); return GetTypedArrayAccessor<Int16Elements>();
} else if (elementsKind == UINT32_ELEMENTS) { } else if (elementsKind == ElementsKind::UINT32_ELEMENTS) {
return GetTypedArrayAccessor<Uint32Elements>(); return GetTypedArrayAccessor<Uint32Elements>();
} }
} }
...@@ -210,37 +211,37 @@ namespace typed_array { ...@@ -210,37 +211,37 @@ namespace typed_array {
macro KindForArrayType<T : type extends ElementsKind>(): macro KindForArrayType<T : type extends ElementsKind>():
constexpr ElementsKind; constexpr ElementsKind;
KindForArrayType<Uint8Elements>(): constexpr ElementsKind { KindForArrayType<Uint8Elements>(): constexpr ElementsKind {
return UINT8_ELEMENTS; return ElementsKind::UINT8_ELEMENTS;
} }
KindForArrayType<Int8Elements>(): constexpr ElementsKind { KindForArrayType<Int8Elements>(): constexpr ElementsKind {
return INT8_ELEMENTS; return ElementsKind::INT8_ELEMENTS;
} }
KindForArrayType<Uint16Elements>(): constexpr ElementsKind { KindForArrayType<Uint16Elements>(): constexpr ElementsKind {
return UINT16_ELEMENTS; return ElementsKind::UINT16_ELEMENTS;
} }
KindForArrayType<Int16Elements>(): constexpr ElementsKind { KindForArrayType<Int16Elements>(): constexpr ElementsKind {
return INT16_ELEMENTS; return ElementsKind::INT16_ELEMENTS;
} }
KindForArrayType<Uint32Elements>(): constexpr ElementsKind { KindForArrayType<Uint32Elements>(): constexpr ElementsKind {
return UINT32_ELEMENTS; return ElementsKind::UINT32_ELEMENTS;
} }
KindForArrayType<Int32Elements>(): constexpr ElementsKind { KindForArrayType<Int32Elements>(): constexpr ElementsKind {
return INT32_ELEMENTS; return ElementsKind::INT32_ELEMENTS;
} }
KindForArrayType<Float32Elements>(): constexpr ElementsKind { KindForArrayType<Float32Elements>(): constexpr ElementsKind {
return FLOAT32_ELEMENTS; return ElementsKind::FLOAT32_ELEMENTS;
} }
KindForArrayType<Float64Elements>(): constexpr ElementsKind { KindForArrayType<Float64Elements>(): constexpr ElementsKind {
return FLOAT64_ELEMENTS; return ElementsKind::FLOAT64_ELEMENTS;
} }
KindForArrayType<Uint8ClampedElements>(): constexpr ElementsKind { KindForArrayType<Uint8ClampedElements>(): constexpr ElementsKind {
return UINT8_CLAMPED_ELEMENTS; return ElementsKind::UINT8_CLAMPED_ELEMENTS;
} }
KindForArrayType<BigUint64Elements>(): constexpr ElementsKind { KindForArrayType<BigUint64Elements>(): constexpr ElementsKind {
return BIGUINT64_ELEMENTS; return ElementsKind::BIGUINT64_ELEMENTS;
} }
KindForArrayType<BigInt64Elements>(): constexpr ElementsKind { KindForArrayType<BigInt64Elements>(): constexpr ElementsKind {
return BIGINT64_ELEMENTS; return ElementsKind::BIGINT64_ELEMENTS;
} }
builtin LoadTypedElement<T : type extends ElementsKind>( builtin LoadTypedElement<T : type extends ElementsKind>(
......
...@@ -20,39 +20,34 @@ extern class NativeContext extends Context; ...@@ -20,39 +20,34 @@ 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>';
type NativeContextSlot generates 'TNode<IntPtrT>' constexpr 'int32_t'; extern enum NativeContextSlot extends intptr constexpr 'Context::Field' {
const ARRAY_BUFFER_FUN_INDEX: constexpr NativeContextSlot ARRAY_BUFFER_FUN_INDEX,
generates 'Context::ARRAY_BUFFER_FUN_INDEX'; ARRAY_BUFFER_NOINIT_FUN_INDEX,
const ARRAY_BUFFER_NOINIT_FUN_INDEX: constexpr NativeContextSlot ARRAY_BUFFER_MAP_INDEX,
generates 'Context::ARRAY_BUFFER_NOINIT_FUN_INDEX'; ARRAY_JOIN_STACK_INDEX,
const ARRAY_BUFFER_MAP_INDEX: constexpr NativeContextSlot OBJECT_FUNCTION_INDEX,
generates 'Context::ARRAY_BUFFER_MAP_INDEX'; ITERATOR_RESULT_MAP_INDEX,
const ARRAY_JOIN_STACK_INDEX: constexpr NativeContextSlot JS_ARRAY_PACKED_ELEMENTS_MAP_INDEX,
generates 'Context::ARRAY_JOIN_STACK_INDEX'; JS_ARRAY_PACKED_SMI_ELEMENTS_MAP_INDEX,
const OBJECT_FUNCTION_INDEX: constexpr NativeContextSlot MATH_RANDOM_CACHE_INDEX,
generates 'Context::OBJECT_FUNCTION_INDEX'; MATH_RANDOM_INDEX_INDEX,
const ITERATOR_RESULT_MAP_INDEX: constexpr NativeContextSlot PROXY_REVOCABLE_RESULT_MAP_INDEX,
generates 'Context::ITERATOR_RESULT_MAP_INDEX'; REFLECT_APPLY_INDEX,
const JS_ARRAY_PACKED_ELEMENTS_MAP_INDEX: constexpr NativeContextSlot REGEXP_FUNCTION_INDEX,
generates 'Context::JS_ARRAY_PACKED_ELEMENTS_MAP_INDEX'; REGEXP_LAST_MATCH_INFO_INDEX,
const JS_ARRAY_PACKED_SMI_ELEMENTS_MAP_INDEX: constexpr NativeContextSlot INITIAL_STRING_ITERATOR_MAP_INDEX,
generates 'Context::JS_ARRAY_PACKED_SMI_ELEMENTS_MAP_INDEX'; SLOW_OBJECT_WITH_NULL_PROTOTYPE_MAP,
const MATH_RANDOM_CACHE_INDEX: constexpr NativeContextSlot
generates 'Context::MATH_RANDOM_CACHE_INDEX'; PROMISE_FUNCTION_INDEX,
const MATH_RANDOM_INDEX_INDEX: constexpr NativeContextSlot PROMISE_THEN_INDEX,
generates 'Context::MATH_RANDOM_INDEX_INDEX'; STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX,
const PROXY_REVOCABLE_RESULT_MAP_INDEX: constexpr NativeContextSlot PROMISE_CAPABILITY_DEFAULT_RESOLVE_SHARED_FUN_INDEX,
generates 'Context::PROXY_REVOCABLE_RESULT_MAP_INDEX'; PROMISE_CAPABILITY_DEFAULT_REJECT_SHARED_FUN_INDEX,
const REFLECT_APPLY_INDEX: constexpr NativeContextSlot PROMISE_GET_CAPABILITIES_EXECUTOR_SHARED_FUN,
generates 'Context::REFLECT_APPLY_INDEX'; PROMISE_PROTOTYPE_INDEX,
const REGEXP_FUNCTION_INDEX: constexpr NativeContextSlot ...
generates 'Context::REGEXP_FUNCTION_INDEX'; }
const REGEXP_LAST_MATCH_INFO_INDEX: constexpr NativeContextSlot
generates 'Context::REGEXP_LAST_MATCH_INFO_INDEX';
const INITIAL_STRING_ITERATOR_MAP_INDEX: constexpr NativeContextSlot
generates 'Context::INITIAL_STRING_ITERATOR_MAP_INDEX';
const SLOW_OBJECT_WITH_NULL_PROTOTYPE_MAP: constexpr NativeContextSlot
generates 'Context::SLOW_OBJECT_WITH_NULL_PROTOTYPE_MAP';
extern operator '[]' macro LoadContextElement( extern operator '[]' macro LoadContextElement(
NativeContext, NativeContextSlot): Object; NativeContext, NativeContextSlot): Object;
extern operator '[]=' macro StoreContextElement( extern operator '[]=' macro StoreContextElement(
......
...@@ -97,9 +97,9 @@ extern macro CalculateNewElementsCapacity(Smi): Smi; ...@@ -97,9 +97,9 @@ extern macro CalculateNewElementsCapacity(Smi): Smi;
extern macro CalculateNewElementsCapacity(intptr): intptr; extern macro CalculateNewElementsCapacity(intptr): intptr;
extern macro AllocateFixedArrayWithHoles( extern macro AllocateFixedArrayWithHoles(
intptr, constexpr AllocationFlags): FixedArray; intptr, constexpr AllocationFlag): FixedArray;
extern macro AllocateFixedDoubleArrayWithHoles( extern macro AllocateFixedDoubleArrayWithHoles(
intptr, constexpr AllocationFlags): FixedDoubleArray; intptr, constexpr AllocationFlag): FixedDoubleArray;
extern macro CopyFixedArrayElements( extern macro CopyFixedArrayElements(
constexpr ElementsKind, FixedArray, constexpr ElementsKind, FixedArray, constexpr ElementsKind, FixedArray, constexpr ElementsKind, FixedArray,
intptr, intptr, intptr): void; intptr, intptr, intptr): void;
...@@ -110,8 +110,8 @@ extern macro CopyFixedArrayElements( ...@@ -110,8 +110,8 @@ extern macro CopyFixedArrayElements(
extern macro ExtractFixedArray(FixedArrayBase, Smi, Smi, Smi): FixedArrayBase; extern macro ExtractFixedArray(FixedArrayBase, Smi, Smi, Smi): FixedArrayBase;
extern macro ExtractFixedArray( extern macro ExtractFixedArray(
FixedArrayBase, Smi, Smi, Smi, FixedArrayBase, Smi, Smi, Smi,
constexpr ExtractFixedArrayFlags): FixedArrayBase; constexpr ExtractFixedArrayFlag): FixedArrayBase;
extern macro ExtractFixedArray( extern macro ExtractFixedArray(
FixedArray, intptr, intptr, intptr, FixedArray, intptr, intptr, intptr,
constexpr ExtractFixedArrayFlags): FixedArray; constexpr ExtractFixedArrayFlag): FixedArray;
...@@ -56,7 +56,7 @@ transient type FastJSArrayForReadWithNoCustomIteration extends ...@@ -56,7 +56,7 @@ transient type FastJSArrayForReadWithNoCustomIteration extends
extern macro AllocateJSArray( extern macro AllocateJSArray(
constexpr ElementsKind, Map, intptr, Smi, constexpr ElementsKind, Map, intptr, Smi,
constexpr AllocationFlags): JSArray; constexpr AllocationFlag): JSArray;
extern macro AllocateJSArray(constexpr ElementsKind, Map, intptr, Smi): JSArray; extern macro AllocateJSArray(constexpr ElementsKind, Map, intptr, Smi): JSArray;
extern macro AllocateJSArray(constexpr ElementsKind, Map, Smi, Smi): JSArray; extern macro AllocateJSArray(constexpr ElementsKind, Map, Smi, Smi): JSArray;
extern macro AllocateJSArray(Map, FixedArrayBase, Smi): JSArray; extern macro AllocateJSArray(Map, FixedArrayBase, Smi): JSArray;
...@@ -108,17 +108,20 @@ extern macro MoveElements( ...@@ -108,17 +108,20 @@ extern macro MoveElements(
macro TorqueMoveElementsSmi( macro TorqueMoveElementsSmi(
elements: FixedArray, dstIndex: intptr, srcIndex: intptr, elements: FixedArray, dstIndex: intptr, srcIndex: intptr,
count: intptr): void { count: intptr): void {
MoveElements(HOLEY_SMI_ELEMENTS, elements, dstIndex, srcIndex, count); MoveElements(
ElementsKind::HOLEY_SMI_ELEMENTS, elements, dstIndex, srcIndex, count);
} }
macro TorqueMoveElements( macro TorqueMoveElements(
elements: FixedArray, dstIndex: intptr, srcIndex: intptr, elements: FixedArray, dstIndex: intptr, srcIndex: intptr,
count: intptr): void { count: intptr): void {
MoveElements(HOLEY_ELEMENTS, elements, dstIndex, srcIndex, count); MoveElements(
ElementsKind::HOLEY_ELEMENTS, elements, dstIndex, srcIndex, count);
} }
macro TorqueMoveElements( macro TorqueMoveElements(
elements: FixedDoubleArray, dstIndex: intptr, srcIndex: intptr, elements: FixedDoubleArray, dstIndex: intptr, srcIndex: intptr,
count: intptr): void { count: intptr): void {
MoveElements(HOLEY_DOUBLE_ELEMENTS, elements, dstIndex, srcIndex, count); MoveElements(
ElementsKind::HOLEY_DOUBLE_ELEMENTS, elements, dstIndex, srcIndex, count);
} }
extern macro CopyElements( extern macro CopyElements(
...@@ -128,14 +131,15 @@ macro TorqueCopyElements( ...@@ -128,14 +131,15 @@ macro TorqueCopyElements(
dstElements: FixedArray, dstIndex: intptr, srcElements: FixedArray, dstElements: FixedArray, dstIndex: intptr, srcElements: FixedArray,
srcIndex: intptr, count: intptr): void { srcIndex: intptr, count: intptr): void {
CopyElements( CopyElements(
HOLEY_ELEMENTS, dstElements, dstIndex, srcElements, srcIndex, count); ElementsKind::HOLEY_ELEMENTS, dstElements, dstIndex, srcElements,
srcIndex, count);
} }
macro TorqueCopyElements( macro TorqueCopyElements(
dstElements: FixedDoubleArray, dstIndex: intptr, dstElements: FixedDoubleArray, dstIndex: intptr,
srcElements: FixedDoubleArray, srcIndex: intptr, count: intptr): void { srcElements: FixedDoubleArray, srcIndex: intptr, count: intptr): void {
CopyElements( CopyElements(
HOLEY_DOUBLE_ELEMENTS, dstElements, dstIndex, srcElements, srcIndex, ElementsKind::HOLEY_DOUBLE_ELEMENTS, dstElements, dstIndex, srcElements,
count); srcIndex, count);
} }
extern builtin CloneFastJSArray(Context, FastJSArrayForCopy): JSArray; extern builtin CloneFastJSArray(Context, FastJSArrayForCopy): JSArray;
...@@ -203,16 +207,17 @@ struct FastJSArrayWitness { ...@@ -203,16 +207,17 @@ struct FastJSArrayWitness {
macro Push(value: JSAny) labels Failed { macro Push(value: JSAny) labels Failed {
assert(this.arrayIsPushable); assert(this.arrayIsPushable);
if (this.hasDoubles) { if (this.hasDoubles) {
BuildAppendJSArray(HOLEY_DOUBLE_ELEMENTS, this.unstable, value) BuildAppendJSArray(
ElementsKind::HOLEY_DOUBLE_ELEMENTS, this.unstable, value)
otherwise Failed; otherwise Failed;
} else if (this.hasSmis) { } else if (this.hasSmis) {
BuildAppendJSArray(HOLEY_SMI_ELEMENTS, this.unstable, value) BuildAppendJSArray(ElementsKind::HOLEY_SMI_ELEMENTS, this.unstable, value)
otherwise Failed; otherwise Failed;
} else { } else {
assert( assert(
this.map.elements_kind == HOLEY_ELEMENTS || this.map.elements_kind == ElementsKind::HOLEY_ELEMENTS ||
this.map.elements_kind == PACKED_ELEMENTS); this.map.elements_kind == ElementsKind::PACKED_ELEMENTS);
BuildAppendJSArray(HOLEY_ELEMENTS, this.unstable, value) BuildAppendJSArray(ElementsKind::HOLEY_ELEMENTS, this.unstable, value)
otherwise Failed; otherwise Failed;
} }
} }
...@@ -250,7 +255,8 @@ macro NewFastJSArrayWitness(array: FastJSArray): FastJSArrayWitness { ...@@ -250,7 +255,8 @@ macro NewFastJSArrayWitness(array: FastJSArray): FastJSArrayWitness {
unstable: array, unstable: array,
map: array.map, map: array.map,
hasDoubles: IsDoubleElementsKind(kind), hasDoubles: IsDoubleElementsKind(kind),
hasSmis: IsElementsKindLessThanOrEqual(kind, HOLEY_SMI_ELEMENTS), hasSmis:
IsElementsKindLessThanOrEqual(kind, ElementsKind::HOLEY_SMI_ELEMENTS),
arrayIsPushable: false arrayIsPushable: false
}; };
} }
......
...@@ -92,7 +92,8 @@ macro AllocateFastOrSlowJSObjectFromMap(implicit context: Context)(map: Map): ...@@ -92,7 +92,8 @@ macro AllocateFastOrSlowJSObjectFromMap(implicit context: Context)(map: Map):
properties = AllocateNameDictionary(kNameDictionaryInitialCapacity); properties = AllocateNameDictionary(kNameDictionaryInitialCapacity);
} }
return AllocateJSObjectFromMap( return AllocateJSObjectFromMap(
map, properties, kEmptyFixedArray, kNone, kWithSlackTracking); map, properties, kEmptyFixedArray, AllocationFlag::kNone,
SlackTrackingMode::kWithSlackTracking);
} }
@generateCppClass @generateCppClass
...@@ -188,4 +189,4 @@ extern macro AllocateJSObjectFromMap( ...@@ -188,4 +189,4 @@ extern macro AllocateJSObjectFromMap(
Map, NameDictionary | EmptyFixedArray | PropertyArray): JSObject; Map, NameDictionary | EmptyFixedArray | PropertyArray): JSObject;
extern macro AllocateJSObjectFromMap( extern macro AllocateJSObjectFromMap(
Map, NameDictionary | EmptyFixedArray | PropertyArray, FixedArray, Map, NameDictionary | EmptyFixedArray | PropertyArray, FixedArray,
constexpr AllocationFlags, constexpr SlackTrackingMode): JSObject; constexpr AllocationFlag, constexpr SlackTrackingMode): JSObject;
...@@ -19,8 +19,8 @@ extern class JSPromise extends JSObject { ...@@ -19,8 +19,8 @@ extern class JSPromise extends JSObject {
} }
macro SetStatus(status: constexpr PromiseState): void { macro SetStatus(status: constexpr PromiseState): void {
assert(this.Status() == kPromisePending); assert(this.Status() == PromiseState::kPending);
assert(status != kPromisePending); assert(status != PromiseState::kPending);
const mask: Smi = SmiConstant(status); const mask: Smi = SmiConstant(status);
this.flags = this.flags | mask; this.flags = this.flags | mask;
......
...@@ -95,6 +95,13 @@ inline std::string GetConstexprName(const std::string& name) { ...@@ -95,6 +95,13 @@ inline std::string GetConstexprName(const std::string& name) {
return CONSTEXPR_TYPE_PREFIX + name; return CONSTEXPR_TYPE_PREFIX + name;
} }
enum class AbstractTypeFlag {
kNone = 0,
kTransient = 1 << 0,
kConstexpr = 1 << 1
};
using AbstractTypeFlags = base::Flags<AbstractTypeFlag>;
enum class ClassFlag { enum class ClassFlag {
kNone = 0, kNone = 0,
kExtern = 1 << 0, kExtern = 1 << 0,
......
...@@ -76,6 +76,13 @@ const Type* Declarations::LookupType(const Identifier* name) { ...@@ -76,6 +76,13 @@ const Type* Declarations::LookupType(const Identifier* name) {
return alias->type(); return alias->type();
} }
base::Optional<const Type*> Declarations::TryLookupType(
const QualifiedName& name) {
auto decls = FilterDeclarables<TypeAlias>(TryLookup(name));
if (decls.empty()) return base::nullopt;
return EnsureUnique(std::move(decls), name, "type")->type();
}
const Type* Declarations::LookupGlobalType(const QualifiedName& name) { const Type* Declarations::LookupGlobalType(const QualifiedName& name) {
TypeAlias* declaration = EnsureUnique( TypeAlias* declaration = EnsureUnique(
FilterDeclarables<TypeAlias>(LookupGlobalScope(name)), name, "type"); FilterDeclarables<TypeAlias>(LookupGlobalScope(name)), name, "type");
......
...@@ -61,6 +61,7 @@ class Declarations { ...@@ -61,6 +61,7 @@ class Declarations {
static const TypeAlias* LookupTypeAlias(const QualifiedName& name); static const TypeAlias* LookupTypeAlias(const QualifiedName& name);
static const Type* LookupType(const QualifiedName& name); static const Type* LookupType(const QualifiedName& name);
static const Type* LookupType(const Identifier* identifier); static const Type* LookupType(const Identifier* identifier);
static base::Optional<const Type*> TryLookupType(const QualifiedName& name);
static const Type* LookupGlobalType(const QualifiedName& name); static const Type* LookupGlobalType(const QualifiedName& name);
static Builtin* FindSomeInternalBuiltinWithType( static Builtin* FindSomeInternalBuiltinWithType(
......
...@@ -1118,6 +1118,182 @@ base::Optional<ParseResult> MakeIfStatement( ...@@ -1118,6 +1118,182 @@ base::Optional<ParseResult> MakeIfStatement(
return ParseResult{result}; return ParseResult{result};
} }
base::Optional<ParseResult> MakeEnumDeclaration(
ParseResultIterator* child_results) {
const bool is_extern = child_results->NextAs<bool>();
auto name_identifier = child_results->NextAs<Identifier*>();
auto name = name_identifier->value;
auto base_identifier = child_results->NextAs<base::Optional<Identifier*>>();
auto constexpr_generates_opt =
child_results->NextAs<base::Optional<std::string>>();
auto entries = child_results->NextAs<std::vector<Identifier*>>();
const bool is_open = child_results->NextAs<bool>();
CurrentSourcePosition::Scope current_source_position(
child_results->matched_input().pos);
if (!is_extern) {
ReportError("non-extern enums are not supported yet");
}
if (!IsValidTypeName(name)) {
NamingConventionError("Type", name, "UpperCamelCase");
}
auto constexpr_generates =
constexpr_generates_opt ? *constexpr_generates_opt : name;
const bool generate_nonconstexpr = base_identifier.has_value();
std::vector<Declaration*> result;
// Build non-constexpr types.
if (generate_nonconstexpr) {
DCHECK(base_identifier.has_value());
if (is_open) {
// For open enumerations, we define an abstract type and inherit all
// entries' types from that:
// type Enum extends Base;
// namespace Enum {
// type kEntry0 extends Enum;
// ...
// type kEntryN extends Enum;
// }
auto type_decl = MakeNode<AbstractTypeDeclaration>(
name_identifier, false, base_identifier, base::nullopt);
std::vector<Declaration*> entry_decls;
for (const auto& entry_name_identifier : entries) {
entry_decls.push_back(MakeNode<AbstractTypeDeclaration>(
entry_name_identifier, false, name_identifier, base::nullopt));
}
result.push_back(type_decl);
result.push_back(
MakeNode<NamespaceDeclaration>(name, std::move(entry_decls)));
} else {
// For closed enumerations, we define abstract types for all entries and
// define the enumeration as a union of those:
// namespace Enum {
// type kEntry0 extends Base;
// ...
// type kEntryN extends Base;
// }
// type Enum = Enum::kEntry0 | ... | Enum::kEntryN;
TypeExpression* union_type = nullptr;
std::vector<Declaration*> entry_decls;
for (const auto& entry_name_identifier : entries) {
entry_decls.push_back(MakeNode<AbstractTypeDeclaration>(
entry_name_identifier, false, base_identifier, base::nullopt));
auto entry_type = MakeNode<BasicTypeExpression>(
std::vector<std::string>{name}, entry_name_identifier->value,
std::vector<TypeExpression*>{});
if (union_type) {
union_type = MakeNode<UnionTypeExpression>(union_type, entry_type);
} else {
union_type = entry_type;
}
}
result.push_back(
MakeNode<NamespaceDeclaration>(name, std::move(entry_decls)));
result.push_back(
MakeNode<TypeAliasDeclaration>(name_identifier, union_type));
}
}
// Build constexpr types.
{
// The constexpr entries inherit from an abstract enumeration type:
// type constexpr Enum extends constexpr Base;
// namespace Enum {
// type constexpr kEntry0 extends constexpr Enum;
// ...
// type constexpr kEntry1 extends constexpr Enum;
// }
Identifier* constexpr_type_identifier =
MakeNode<Identifier>(std::string(CONSTEXPR_TYPE_PREFIX) + name);
base::Optional<Identifier*> base_constexpr_type_identifier = base::nullopt;
if (base_identifier) {
base_constexpr_type_identifier = MakeNode<Identifier>(
std::string(CONSTEXPR_TYPE_PREFIX) + (*base_identifier)->value);
}
result.push_back(MakeNode<AbstractTypeDeclaration>(
constexpr_type_identifier, false, base_constexpr_type_identifier,
constexpr_generates));
TypeExpression* type_expr = nullptr;
Identifier* fromconstexpr_identifier = nullptr;
Identifier* fromconstexpr_parameter_identifier = nullptr;
Statement* fromconstexpr_body = nullptr;
if (generate_nonconstexpr) {
DCHECK(base_identifier.has_value());
TypeExpression* base_type_expr = MakeNode<BasicTypeExpression>(
std::vector<std::string>{}, (*base_identifier)->value,
std::vector<TypeExpression*>{});
type_expr = MakeNode<BasicTypeExpression>(
std::vector<std::string>{}, name, std::vector<TypeExpression*>{});
// return %RawDownCast<Enum>(%FromConstexpr<Base>(o)))
fromconstexpr_identifier = MakeNode<Identifier>("FromConstexpr");
fromconstexpr_parameter_identifier = MakeNode<Identifier>("o");
fromconstexpr_body =
MakeNode<ReturnStatement>(MakeNode<IntrinsicCallExpression>(
MakeNode<Identifier>("%RawDownCast"),
std::vector<TypeExpression*>{type_expr},
std::vector<Expression*>{MakeNode<IntrinsicCallExpression>(
MakeNode<Identifier>("%FromConstexpr"),
std::vector<TypeExpression*>{base_type_expr},
std::vector<Expression*>{MakeNode<IdentifierExpression>(
std::vector<std::string>{},
fromconstexpr_parameter_identifier)})}));
}
std::vector<Declaration*> entry_decls;
for (const auto& entry_name_identifier : entries) {
const std::string entry_name = entry_name_identifier->value;
const std::string entry_constexpr_type =
std::string(CONSTEXPR_TYPE_PREFIX) + entry_name;
entry_decls.push_back(MakeNode<AbstractTypeDeclaration>(
MakeNode<Identifier>(entry_constexpr_type), false,
constexpr_type_identifier, constexpr_generates));
// namespace Enum {
// const kEntry0: constexpr kEntry0 constexpr 'Enum::kEntry0';
// }
entry_decls.push_back(MakeNode<ExternConstDeclaration>(
entry_name_identifier,
MakeNode<BasicTypeExpression>(std::vector<std::string>{},
entry_constexpr_type,
std::vector<TypeExpression*>{}),
constexpr_generates + "::" + entry_name));
// FromConstexpr<Enum, Enum::constexpr kEntry0>(
// : Enum::constexpr kEntry0): Enum
if (generate_nonconstexpr) {
TypeExpression* entry_constexpr_type_expr =
MakeNode<BasicTypeExpression>(std::vector<std::string>{name},
entry_constexpr_type,
std::vector<TypeExpression*>{});
ParameterList parameters;
parameters.names.push_back(fromconstexpr_parameter_identifier);
parameters.types.push_back(entry_constexpr_type_expr);
result.push_back(MakeNode<SpecializationDeclaration>(
false, fromconstexpr_identifier,
std::vector<TypeExpression*>{type_expr, entry_constexpr_type_expr},
std::move(parameters), type_expr, LabelAndTypesVector{},
fromconstexpr_body));
}
}
result.push_back(
MakeNode<NamespaceDeclaration>(name, std::move(entry_decls)));
}
return ParseResult{std::move(result)};
}
base::Optional<ParseResult> MakeTypeswitchStatement( base::Optional<ParseResult> MakeTypeswitchStatement(
ParseResultIterator* child_results) { ParseResultIterator* child_results) {
auto expression = child_results->NextAs<Expression*>(); auto expression = child_results->NextAs<Expression*>();
...@@ -2189,7 +2365,14 @@ struct TorqueGrammar : Grammar { ...@@ -2189,7 +2365,14 @@ struct TorqueGrammar : Grammar {
&optionalReturnType, optionalLabelList, &block}, &optionalReturnType, optionalLabelList, &block},
AsSingletonVector<Declaration*, MakeSpecializationDeclaration>()), AsSingletonVector<Declaration*, MakeSpecializationDeclaration>()),
Rule({Token("#include"), &externalString}, Rule({Token("#include"), &externalString},
AsSingletonVector<Declaration*, MakeCppIncludeDeclaration>())}; AsSingletonVector<Declaration*, MakeCppIncludeDeclaration>()),
Rule({CheckIf(Token("extern")), Token("enum"), &name,
Optional<Identifier*>(Sequence({Token("extends"), &name})),
Optional<std::string>(
Sequence({Token("constexpr"), &externalString})),
Token("{"), NonemptyList<Identifier*>(&name, Token(",")),
CheckIf(Sequence({Token(","), Token("...")})), Token("}")},
MakeEnumDeclaration)};
// Result: std::vector<Declaration*> // Result: std::vector<Declaration*>
Symbol declarationList = { Symbol declarationList = {
......
...@@ -20,17 +20,18 @@ namespace torque { ...@@ -20,17 +20,18 @@ namespace torque {
class TypeOracle : public ContextualClass<TypeOracle> { class TypeOracle : public ContextualClass<TypeOracle> {
public: public:
static const AbstractType* GetAbstractType( static const AbstractType* GetAbstractType(
const Type* parent, std::string name, bool transient, const Type* parent, std::string name, AbstractTypeFlags flags,
std::string generated, const AbstractType* non_constexpr_version, std::string generated, const Type* non_constexpr_version,
MaybeSpecializationKey specialized_from) { MaybeSpecializationKey specialized_from) {
auto ptr = std::unique_ptr<AbstractType>(new AbstractType( auto ptr = std::unique_ptr<AbstractType>(
parent, transient, std::move(name), std::move(generated), new AbstractType(parent, flags, std::move(name), std::move(generated),
non_constexpr_version, specialized_from)); non_constexpr_version, specialized_from));
const AbstractType* result = ptr.get(); const AbstractType* result = ptr.get();
Get().nominal_types_.push_back(std::move(ptr));
if (non_constexpr_version) { if (non_constexpr_version) {
DCHECK(ptr->IsConstexpr());
non_constexpr_version->SetConstexprVersion(result); non_constexpr_version->SetConstexprVersion(result);
} }
Get().nominal_types_.push_back(std::move(ptr));
return result; return result;
} }
......
...@@ -98,18 +98,21 @@ const AbstractType* TypeVisitor::ComputeType( ...@@ -98,18 +98,21 @@ const AbstractType* TypeVisitor::ComputeType(
ReportError("cannot declare a transient type that is also constexpr"); ReportError("cannot declare a transient type that is also constexpr");
} }
const AbstractType* non_constexpr_version = nullptr; const Type* non_constexpr_version = nullptr;
if (decl->is_constexpr) { if (decl->is_constexpr) {
QualifiedName non_constexpr_name{GetNonConstexprName(decl->name->value)}; QualifiedName non_constexpr_name{GetNonConstexprName(decl->name->value)};
const Type* non_constexpr_type = if (auto type = Declarations::TryLookupType(non_constexpr_name)) {
Declarations::LookupType(non_constexpr_name); non_constexpr_version = *type;
non_constexpr_version = AbstractType::DynamicCast(non_constexpr_type);
DCHECK_NOT_NULL(non_constexpr_version);
} }
}
AbstractTypeFlags flags = AbstractTypeFlag::kNone;
if (decl->transient) flags |= AbstractTypeFlag::kTransient;
if (decl->is_constexpr) flags |= AbstractTypeFlag::kConstexpr;
return TypeOracle::GetAbstractType(parent_type, decl->name->value, return TypeOracle::GetAbstractType(parent_type, decl->name->value, flags,
decl->transient, generates, generates, non_constexpr_version,
non_constexpr_version, specialized_from); specialized_from);
} }
void DeclareMethods(AggregateType* container_type, void DeclareMethods(AggregateType* container_type,
......
...@@ -17,16 +17,19 @@ namespace torque { ...@@ -17,16 +17,19 @@ namespace torque {
// This custom copy constructor doesn't copy aliases_ and id_ because they // This custom copy constructor doesn't copy aliases_ and id_ because they
// should be distinct for each type. // should be distinct for each type.
Type::Type(const Type& other) V8_NOEXCEPT : TypeBase(other), Type::Type(const Type& other) V8_NOEXCEPT
: TypeBase(other),
parent_(other.parent_), parent_(other.parent_),
aliases_(), aliases_(),
id_(TypeOracle::FreshTypeId()) {} id_(TypeOracle::FreshTypeId()),
constexpr_version_(other.constexpr_version_) {}
Type::Type(TypeBase::Kind kind, const Type* parent, Type::Type(TypeBase::Kind kind, const Type* parent,
MaybeSpecializationKey specialized_from) MaybeSpecializationKey specialized_from)
: TypeBase(kind), : TypeBase(kind),
parent_(parent), parent_(parent),
id_(TypeOracle::FreshTypeId()), id_(TypeOracle::FreshTypeId()),
specialized_from_(specialized_from) {} specialized_from_(specialized_from),
constexpr_version_(nullptr) {}
std::string Type::ToString() const { std::string Type::ToString() const {
if (aliases_.size() == 0) if (aliases_.size() == 0)
......
...@@ -128,7 +128,6 @@ class V8_EXPORT_PRIVATE Type : public TypeBase { ...@@ -128,7 +128,6 @@ class V8_EXPORT_PRIVATE Type : public TypeBase {
} }
virtual bool IsTransient() const { return false; } virtual bool IsTransient() const { return false; }
virtual const Type* NonConstexprVersion() const { return this; } virtual const Type* NonConstexprVersion() const { return this; }
virtual const Type* ConstexprVersion() const { return nullptr; }
std::string GetConstexprGeneratedTypeName() const; std::string GetConstexprGeneratedTypeName() const;
base::Optional<const ClassType*> ClassSupertype() const; base::Optional<const ClassType*> ClassSupertype() const;
virtual std::vector<RuntimeType> GetRuntimeTypes() const { return {}; } virtual std::vector<RuntimeType> GetRuntimeTypes() const { return {}; }
...@@ -143,6 +142,15 @@ class V8_EXPORT_PRIVATE Type : public TypeBase { ...@@ -143,6 +142,15 @@ class V8_EXPORT_PRIVATE Type : public TypeBase {
static std::string ComputeName(const std::string& basename, static std::string ComputeName(const std::string& basename,
MaybeSpecializationKey specialized_from); MaybeSpecializationKey specialized_from);
virtual void SetConstexprVersion(const Type* type) const {
constexpr_version_ = type;
}
virtual const Type* ConstexprVersion() const {
if (constexpr_version_) return constexpr_version_;
if (IsConstexpr()) return this;
return nullptr;
}
protected: protected:
Type(TypeBase::Kind kind, const Type* parent, Type(TypeBase::Kind kind, const Type* parent,
...@@ -165,6 +173,7 @@ class V8_EXPORT_PRIVATE Type : public TypeBase { ...@@ -165,6 +173,7 @@ class V8_EXPORT_PRIVATE Type : public TypeBase {
mutable std::set<std::string> aliases_; mutable std::set<std::string> aliases_;
size_t id_; size_t id_;
MaybeSpecializationKey specialized_from_; MaybeSpecializationKey specialized_from_;
mutable const Type* constexpr_version_ = nullptr;
}; };
inline size_t hash_value(const TypeVector& types) { inline size_t hash_value(const TypeVector& types) {
...@@ -246,9 +255,9 @@ class AbstractType final : public Type { ...@@ -246,9 +255,9 @@ class AbstractType final : public Type {
return IsConstexpr() ? generated_type_ : "TNode<" + generated_type_ + ">"; return IsConstexpr() ? generated_type_ : "TNode<" + generated_type_ + ">";
} }
std::string GetGeneratedTNodeTypeNameImpl() const override; std::string GetGeneratedTNodeTypeNameImpl() const override;
bool IsConstexpr() const override { bool IsConstexpr() const final {
bool is_constexpr = non_constexpr_version_ != nullptr; const bool is_constexpr = flags_ & AbstractTypeFlag::kConstexpr;
DCHECK_EQ(is_constexpr, IsConstexprName(name())); DCHECK_IMPLIES(non_constexpr_version_ != nullptr, is_constexpr);
return is_constexpr; return is_constexpr;
} }
...@@ -258,29 +267,23 @@ class AbstractType final : public Type { ...@@ -258,29 +267,23 @@ class AbstractType final : public Type {
return nullptr; return nullptr;
} }
const AbstractType* ConstexprVersion() const override {
if (constexpr_version_) return constexpr_version_;
if (IsConstexpr()) return this;
return nullptr;
}
std::vector<RuntimeType> GetRuntimeTypes() const override; std::vector<RuntimeType> GetRuntimeTypes() const override;
private: private:
friend class TypeOracle; friend class TypeOracle;
AbstractType(const Type* parent, bool transient, const std::string& name, AbstractType(const Type* parent, AbstractTypeFlags flags,
const std::string& generated_type, const std::string& name, const std::string& generated_type,
const Type* non_constexpr_version, const Type* non_constexpr_version,
MaybeSpecializationKey specialized_from) MaybeSpecializationKey specialized_from)
: Type(Kind::kAbstractType, parent, specialized_from), : Type(Kind::kAbstractType, parent, specialized_from),
transient_(transient), flags_(flags),
name_(name), name_(name),
generated_type_(generated_type), generated_type_(generated_type),
non_constexpr_version_(non_constexpr_version) { non_constexpr_version_(non_constexpr_version) {
if (parent) DCHECK(parent->IsConstexpr() == IsConstexpr()); if (parent) DCHECK_EQ(parent->IsConstexpr(), IsConstexpr());
DCHECK_EQ(!IsConstexprName(name), non_constexpr_version == nullptr); DCHECK_EQ(IsConstexprName(name), IsConstexpr());
DCHECK_IMPLIES(IsConstexprName(name), DCHECK_IMPLIES(non_constexpr_version_ != nullptr, IsConstexpr());
!non_constexpr_version->IsConstexpr()); DCHECK(!(IsConstexpr() && (flags_ & AbstractTypeFlag::kTransient)));
} }
std::string SimpleNameImpl() const override { std::string SimpleNameImpl() const override {
...@@ -289,18 +292,14 @@ class AbstractType final : public Type { ...@@ -289,18 +292,14 @@ class AbstractType final : public Type {
return name(); return name();
} }
void SetConstexprVersion(const AbstractType* type) const { bool IsTransient() const override {
DCHECK_EQ(GetConstexprName(name()), type->name()); return flags_ & AbstractTypeFlag::kTransient;
constexpr_version_ = type;
} }
bool IsTransient() const override { return transient_; } AbstractTypeFlags flags_;
bool transient_;
const std::string name_; const std::string name_;
const std::string generated_type_; const std::string generated_type_;
const Type* non_constexpr_version_; const Type* non_constexpr_version_;
mutable const AbstractType* constexpr_version_ = nullptr;
}; };
// For now, builtin pointers are restricted to Torque-defined builtins. // For now, builtin pointers are restricted to Torque-defined builtins.
...@@ -472,6 +471,7 @@ class V8_EXPORT_PRIVATE BitFieldStructType final : public Type { ...@@ -472,6 +471,7 @@ class V8_EXPORT_PRIVATE BitFieldStructType final : public Type {
return {{parent()->GetGeneratedTNodeTypeName(), ""}}; return {{parent()->GetGeneratedTNodeTypeName(), ""}};
} }
void SetConstexprVersion(const Type*) const override { UNREACHABLE(); }
const Type* ConstexprVersion() const override { const Type* ConstexprVersion() const override {
return parent()->ConstexprVersion(); return parent()->ConstexprVersion();
} }
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
namespace test { namespace test {
macro ElementsKindTestHelper1(kind: constexpr ElementsKind): bool { macro ElementsKindTestHelper1(kind: constexpr ElementsKind): bool {
if constexpr ((kind == UINT8_ELEMENTS) || (kind == UINT16_ELEMENTS)) { if constexpr (
(kind == ElementsKind::UINT8_ELEMENTS) ||
(kind == ElementsKind::UINT16_ELEMENTS)) {
return true; return true;
} else { } else {
return false; return false;
...@@ -12,7 +14,9 @@ namespace test { ...@@ -12,7 +14,9 @@ namespace test {
} }
macro ElementsKindTestHelper2(kind: constexpr ElementsKind): constexpr bool { macro ElementsKindTestHelper2(kind: constexpr ElementsKind): constexpr bool {
return ((kind == UINT8_ELEMENTS) || (kind == UINT16_ELEMENTS)); return (
(kind == ElementsKind::UINT8_ELEMENTS) ||
(kind == ElementsKind::UINT16_ELEMENTS));
} }
macro LabelTestHelper1(): never macro LabelTestHelper1(): never
...@@ -32,22 +36,27 @@ namespace test { ...@@ -32,22 +36,27 @@ namespace test {
@export @export
macro TestConstexpr1() { macro TestConstexpr1() {
check(FromConstexpr<bool>(IsFastElementsKind(PACKED_SMI_ELEMENTS))); check(FromConstexpr<bool>(
IsFastElementsKind(ElementsKind::PACKED_SMI_ELEMENTS)));
} }
@export @export
macro TestConstexprIf() { macro TestConstexprIf() {
check(ElementsKindTestHelper1(UINT8_ELEMENTS)); check(ElementsKindTestHelper1(ElementsKind::UINT8_ELEMENTS));
check(ElementsKindTestHelper1(UINT16_ELEMENTS)); check(ElementsKindTestHelper1(ElementsKind::UINT16_ELEMENTS));
check(!ElementsKindTestHelper1(UINT32_ELEMENTS)); check(!ElementsKindTestHelper1(ElementsKind::UINT32_ELEMENTS));
} }
@export @export
macro TestConstexprReturn() { macro TestConstexprReturn() {
check(FromConstexpr<bool>(ElementsKindTestHelper2(UINT8_ELEMENTS))); check(FromConstexpr<bool>(
check(FromConstexpr<bool>(ElementsKindTestHelper2(UINT16_ELEMENTS))); ElementsKindTestHelper2(ElementsKind::UINT8_ELEMENTS)));
check(!FromConstexpr<bool>(ElementsKindTestHelper2(UINT32_ELEMENTS))); check(FromConstexpr<bool>(
check(FromConstexpr<bool>(!ElementsKindTestHelper2(UINT32_ELEMENTS))); ElementsKindTestHelper2(ElementsKind::UINT16_ELEMENTS)));
check(!FromConstexpr<bool>(
ElementsKindTestHelper2(ElementsKind::UINT32_ELEMENTS)));
check(FromConstexpr<bool>(
!ElementsKindTestHelper2(ElementsKind::UINT32_ELEMENTS)));
} }
@export @export
...@@ -633,7 +642,7 @@ namespace test { ...@@ -633,7 +642,7 @@ namespace test {
macro TestCatch1(implicit context: Context)(): Smi { macro TestCatch1(implicit context: Context)(): Smi {
let r: Smi = 0; let r: Smi = 0;
try { try {
ThrowTypeError(kInvalidArrayLength); ThrowTypeError(MessageTemplate::kInvalidArrayLength);
} catch (_e) { } catch (_e) {
r = 1; r = 1;
return r; return r;
...@@ -642,7 +651,7 @@ namespace test { ...@@ -642,7 +651,7 @@ namespace test {
@export @export
macro TestCatch2Wrapper(implicit context: Context)(): never { macro TestCatch2Wrapper(implicit context: Context)(): never {
ThrowTypeError(kInvalidArrayLength); ThrowTypeError(MessageTemplate::kInvalidArrayLength);
} }
@export @export
...@@ -659,7 +668,7 @@ namespace test { ...@@ -659,7 +668,7 @@ namespace test {
@export @export
macro TestCatch3WrapperWithLabel(implicit context: Context)(): macro TestCatch3WrapperWithLabel(implicit context: Context)():
never labels _Abort { never labels _Abort {
ThrowTypeError(kInvalidArrayLength); ThrowTypeError(MessageTemplate::kInvalidArrayLength);
} }
@export @export
......
...@@ -71,7 +71,32 @@ type BuiltinPtr extends Smi generates 'TNode<BuiltinPtr>'; ...@@ -71,7 +71,32 @@ type BuiltinPtr extends Smi generates 'TNode<BuiltinPtr>';
type Context extends HeapObject generates 'TNode<Context>'; type Context extends HeapObject generates 'TNode<Context>';
type NativeContext extends Context; type NativeContext extends Context;
intrinsic %FromConstexpr<To: type, From: type>(b: From): To;
intrinsic %RawDownCast<To: type, From: type>(x: From): To;
intrinsic %RawConstexprCast<To: type, From: type>(f: From): To;
extern macro SmiConstant(constexpr Smi): Smi;
extern macro TaggedToSmi(Object): Smi
labels CastError;
extern macro TaggedToHeapObject(Object): HeapObject
labels CastError;
macro FromConstexpr<To: type, From: type>(o: From): To; macro FromConstexpr<To: type, From: type>(o: From): To;
FromConstexpr<Smi, constexpr Smi>(s: constexpr Smi): Smi {
return SmiConstant(s);
}
FromConstexpr<Smi, constexpr int31>(s: constexpr int31): Smi {
return %FromConstexpr<Smi>(s);
}
macro Cast<A : type extends Object>(implicit context: Context)(o: Object): A
labels CastError {
return Cast<A>(TaggedToHeapObject(o) otherwise CastError)
otherwise CastError;
}
Cast<Smi>(o: Object): Smi
labels CastError {
return TaggedToSmi(o) otherwise CastError;
}
)"; )";
TorqueCompilerResult TestCompileTorque(std::string source) { TorqueCompilerResult TestCompileTorque(std::string source) {
...@@ -515,6 +540,69 @@ TEST(Torque, SpecializationRequesters) { ...@@ -515,6 +540,69 @@ TEST(Torque, SpecializationRequesters) {
} }
#endif #endif
TEST(Torque, Enums) {
ExpectSuccessfulCompilation(R"(
extern enum MyEnum {
kValue0,
kValue1,
kValue2,
kValue3
}
)");
ExpectFailingCompilation(R"(
extern enum MyEmptyEnum {
}
)",
HasSubstr("unexpected token \"}\""));
}
TEST(Torque, EnumInTypeswitch) {
ExpectSuccessfulCompilation(R"(
extern enum MyEnum extends Smi {
kA,
kB,
kC
}
@export
macro Test(implicit context: Context)(v : MyEnum): Smi {
typeswitch(v) {
case (MyEnum::kA | MyEnum::kB): {
return 1;
}
case (MyEnum::kC): {
return 2;
}
}
}
)");
ExpectSuccessfulCompilation(R"(
extern enum MyEnum extends Smi {
kA,
kB,
kC,
...
}
@export
macro Test(implicit context: Context)(v : MyEnum): Smi {
typeswitch(v) {
case (MyEnum::kC): {
return 2;
}
case (MyEnum::kA | MyEnum::kB): {
return 1;
}
case (MyEnum): {
return 0;
}
}
}
)");
}
} // namespace torque } // namespace torque
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -303,7 +303,7 @@ namespace array { ...@@ -303,7 +303,7 @@ namespace array {
transitioning builtin Delete<ElementsAccessor : type extends ElementsKind>( transitioning builtin Delete<ElementsAccessor : type extends ElementsKind>(
context: Context, sortState: SortState, index: Smi): Smi { context: Context, sortState: SortState, index: Smi): Smi {
const receiver = sortState.receiver; const receiver = sortState.receiver;
DeleteProperty(receiver, index, kStrict); DeleteProperty(receiver, index, LanguageMode::kStrict);
return kSuccess; return kSuccess;
} }
...@@ -1394,7 +1394,7 @@ namespace array { ...@@ -1394,7 +1394,7 @@ namespace array {
// throw a TypeError exception. // throw a TypeError exception.
const comparefnObj: JSAny = arguments[0]; const comparefnObj: JSAny = arguments[0];
const comparefn = Cast<(Undefined | Callable)>(comparefnObj) otherwise const comparefn = Cast<(Undefined | Callable)>(comparefnObj) otherwise
ThrowTypeError(kBadSortComparisonFunction, comparefnObj); ThrowTypeError(MessageTemplate::kBadSortComparisonFunction, comparefnObj);
// 2. Let obj be ? ToObject(this value). // 2. Let obj be ? ToObject(this value).
const obj: JSReceiver = ToObject(context, receiver); const obj: JSReceiver = ToObject(context, receiver);
......
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