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