[torque] Add lint error for 'let' bindings that can be 'const'
This CL adds a lint error for variables that are unnecessarily bound with 'let' when they could be bound using 'const. This test is skipped for struct types. For struct types, the "constness" also depends on the struct methods called and whether these methods write to the struct or not. This is not straight-forward to detect. Drive-by: Fix all the newly introduced lint errors. Bug: v8:7793 Change-Id: I0522ffcc4321350eef2e9573b8430bc78200ddce Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1645322 Commit-Queue: Simon Zünd <szuend@chromium.org> Reviewed-by: Tobias Tebbi <tebbi@chromium.org> Cr-Commit-Position: refs/heads/master@{#62085}
This commit is contained in:
parent
7304d116d3
commit
da6543108d
@ -34,13 +34,13 @@ namespace arguments {
|
||||
@export
|
||||
macro GetArgumentsFrameAndCount(implicit context: Context)(f: JSFunction):
|
||||
ArgumentsInfo {
|
||||
let frame: Frame = LoadParentFramePointer();
|
||||
const frame: Frame = LoadParentFramePointer();
|
||||
assert(frame.function == f);
|
||||
|
||||
const shared: SharedFunctionInfo = f.shared_function_info;
|
||||
const formalParameterCount: bint =
|
||||
Convert<bint>(Convert<int32>(shared.formal_parameter_count));
|
||||
let argumentCount: bint = formalParameterCount;
|
||||
const argumentCount: bint = formalParameterCount;
|
||||
|
||||
const adaptor: ArgumentsAdaptorFrame =
|
||||
Cast<ArgumentsAdaptorFrame>(frame.caller)
|
||||
|
@ -88,7 +88,7 @@ namespace array {
|
||||
labels Bailout(Smi) {
|
||||
let k: Smi = 0;
|
||||
const smiLen = Cast<Smi>(len) otherwise goto Bailout(k);
|
||||
let fastO: FastJSArray = Cast<FastJSArray>(o) otherwise goto Bailout(k);
|
||||
const fastO: FastJSArray = Cast<FastJSArray>(o) otherwise goto Bailout(k);
|
||||
let fastOW = NewFastJSArrayWitness(fastO);
|
||||
|
||||
// Build a fast loop over the smi array.
|
||||
|
@ -45,7 +45,7 @@ namespace array_find {
|
||||
// JSReceiver.
|
||||
const jsreceiver = Cast<JSReceiver>(receiver) otherwise unreachable;
|
||||
const callbackfn = Cast<Callable>(callback) otherwise unreachable;
|
||||
let numberK = Cast<Number>(initialK) otherwise unreachable;
|
||||
const numberK = Cast<Number>(initialK) otherwise unreachable;
|
||||
const numberLength = Cast<Number>(length) otherwise unreachable;
|
||||
|
||||
// This custom lazy deopt point is right after the callback. find() needs
|
||||
|
@ -46,7 +46,7 @@ namespace array_findindex {
|
||||
// JSReceiver.
|
||||
const jsreceiver = Cast<JSReceiver>(receiver) otherwise unreachable;
|
||||
const callbackfn = Cast<Callable>(callback) otherwise unreachable;
|
||||
let numberK = Cast<Number>(initialK) otherwise unreachable;
|
||||
const numberK = Cast<Number>(initialK) otherwise unreachable;
|
||||
const numberLength = Cast<Number>(length) otherwise unreachable;
|
||||
|
||||
// This custom lazy deopt point is right after the callback. find() needs
|
||||
|
@ -72,7 +72,7 @@ namespace array_foreach {
|
||||
labels Bailout(Smi) {
|
||||
let k: Smi = 0;
|
||||
const smiLen = Cast<Smi>(len) otherwise goto Bailout(k);
|
||||
let fastO = Cast<FastJSArray>(o) otherwise goto Bailout(k);
|
||||
const fastO = Cast<FastJSArray>(o) otherwise goto Bailout(k);
|
||||
let fastOW = NewFastJSArrayWitness(fastO);
|
||||
|
||||
// Build a fast loop over the smi array.
|
||||
|
@ -535,7 +535,7 @@ namespace array_join {
|
||||
sepObj: Object, locales: Object, options: Object): Object {
|
||||
// 3. If separator is undefined, let sep be the single-element String ",".
|
||||
// 4. Else, let sep be ? ToString(separator).
|
||||
let sep: String =
|
||||
const sep: String =
|
||||
sepObj == Undefined ? ',' : ToString_Inline(context, sepObj);
|
||||
|
||||
// If the receiver is not empty and not already being joined, continue with
|
||||
|
@ -94,7 +94,7 @@ namespace array_map {
|
||||
}
|
||||
|
||||
CreateJSArray(implicit context: Context)(validLength: Smi): JSArray {
|
||||
let length: Smi = this.fixedArray.length;
|
||||
const length: Smi = this.fixedArray.length;
|
||||
assert(validLength <= length);
|
||||
let kind: ElementsKind = PACKED_SMI_ELEMENTS;
|
||||
if (!this.onlySmis) {
|
||||
@ -114,7 +114,7 @@ namespace array_map {
|
||||
kind = FastHoleyElementsKind(kind);
|
||||
}
|
||||
|
||||
let map: Map = LoadJSArrayElementsMap(kind, LoadNativeContext(context));
|
||||
const map: Map = LoadJSArrayElementsMap(kind, LoadNativeContext(context));
|
||||
let a: JSArray;
|
||||
|
||||
if (IsDoubleElementsKind(kind)) {
|
||||
|
@ -35,7 +35,7 @@ namespace array_of {
|
||||
// 7. Repeat, while k < len
|
||||
while (k < len) {
|
||||
// a. Let kValue be items[k].
|
||||
let kValue: Object = items[Convert<intptr>(k)];
|
||||
const kValue: Object = items[Convert<intptr>(k)];
|
||||
|
||||
// b. Let Pk be ! ToString(k).
|
||||
// c. Perform ? CreateDataPropertyOrThrow(A, Pk, kValue).
|
||||
|
@ -53,11 +53,11 @@ namespace array {
|
||||
// JSReceiver.
|
||||
const jsreceiver = Cast<JSReceiver>(receiver) otherwise unreachable;
|
||||
const callbackfn = Cast<Callable>(callback) otherwise unreachable;
|
||||
let numberK = Cast<Number>(initialK) otherwise unreachable;
|
||||
const numberK = Cast<Number>(initialK) otherwise unreachable;
|
||||
const numberLength = Cast<Number>(length) otherwise unreachable;
|
||||
|
||||
// The accumulator is the result from the callback call which just occured.
|
||||
let r = ArrayReduceRightLoopContinuation(
|
||||
const r = ArrayReduceRightLoopContinuation(
|
||||
jsreceiver, callbackfn, result, jsreceiver, numberK, numberLength);
|
||||
return r;
|
||||
}
|
||||
@ -111,7 +111,7 @@ namespace array {
|
||||
labels Bailout(Number, Object) {
|
||||
let accumulator = initialAccumulator;
|
||||
const smiLen = Cast<Smi>(len) otherwise goto Bailout(len - 1, accumulator);
|
||||
let fastO =
|
||||
const fastO =
|
||||
Cast<FastJSArray>(o) otherwise goto Bailout(len - 1, accumulator);
|
||||
let fastOW = NewFastJSArrayWitness(fastO);
|
||||
|
||||
|
@ -53,11 +53,11 @@ namespace array {
|
||||
// JSReceiver.
|
||||
const jsreceiver = Cast<JSReceiver>(receiver) otherwise unreachable;
|
||||
const callbackfn = Cast<Callable>(callback) otherwise unreachable;
|
||||
let numberK = Cast<Number>(initialK) otherwise unreachable;
|
||||
const numberK = Cast<Number>(initialK) otherwise unreachable;
|
||||
const numberLength = Cast<Number>(length) otherwise unreachable;
|
||||
|
||||
// The accumulator is the result from the callback call which just occured.
|
||||
let r = ArrayReduceLoopContinuation(
|
||||
const r = ArrayReduceLoopContinuation(
|
||||
jsreceiver, callbackfn, result, jsreceiver, numberK, numberLength);
|
||||
return r;
|
||||
}
|
||||
@ -111,7 +111,7 @@ namespace array {
|
||||
const k = 0;
|
||||
let accumulator = initialAccumulator;
|
||||
Cast<Smi>(len) otherwise goto Bailout(k, accumulator);
|
||||
let fastO = Cast<FastJSArray>(o) otherwise goto Bailout(k, accumulator);
|
||||
const fastO = Cast<FastJSArray>(o) otherwise goto Bailout(k, accumulator);
|
||||
let fastOW = NewFastJSArrayWitness(fastO);
|
||||
|
||||
// Build a fast loop over the array.
|
||||
|
@ -185,7 +185,7 @@ namespace array_slice {
|
||||
// 10. Repeat, while k < final
|
||||
while (k < final) {
|
||||
// a. Let Pk be ! ToString(k).
|
||||
let pK: Number = k;
|
||||
const pK: Number = k;
|
||||
|
||||
// b. Let kPresent be ? HasProperty(O, Pk).
|
||||
const fromPresent: Boolean = HasProperty(o, pK);
|
||||
|
@ -88,7 +88,7 @@ namespace array {
|
||||
labels Bailout(Smi) {
|
||||
let k: Smi = 0;
|
||||
const smiLen = Cast<Smi>(len) otherwise goto Bailout(k);
|
||||
let fastO = Cast<FastJSArray>(o) otherwise goto Bailout(k);
|
||||
const fastO = Cast<FastJSArray>(o) otherwise goto Bailout(k);
|
||||
let fastOW = NewFastJSArrayWitness(fastO);
|
||||
|
||||
// Build a fast loop over the smi array.
|
||||
|
@ -76,7 +76,7 @@ namespace array_splice {
|
||||
UnsafeCast<FixedArrayType>(elements), dstIndex, srcIndex, count);
|
||||
} else {
|
||||
// Grow.
|
||||
let capacity: Smi = CalculateNewElementsCapacity(newLength);
|
||||
const capacity: Smi = CalculateNewElementsCapacity(newLength);
|
||||
const newElements: FixedArrayType =
|
||||
Extract<FixedArrayType>(elements, 0, actualStart, capacity);
|
||||
a.elements = newElements;
|
||||
|
@ -2599,9 +2599,9 @@ LoadElementNoHole<FixedArray>(implicit context: Context)(
|
||||
a: JSArray, index: Smi): Object
|
||||
labels IfHole {
|
||||
try {
|
||||
let elements: FixedArray =
|
||||
const elements: FixedArray =
|
||||
Cast<FixedArray>(a.elements) otherwise Unexpected;
|
||||
let e: Object = elements.objects[index];
|
||||
const e: Object = elements.objects[index];
|
||||
if (e == Hole) {
|
||||
goto IfHole;
|
||||
}
|
||||
@ -2616,9 +2616,10 @@ LoadElementNoHole<FixedDoubleArray>(implicit context: Context)(
|
||||
a: JSArray, index: Smi): Object
|
||||
labels IfHole {
|
||||
try {
|
||||
let elements: FixedDoubleArray =
|
||||
const elements: FixedDoubleArray =
|
||||
Cast<FixedDoubleArray>(a.elements) otherwise Unexpected;
|
||||
let e: float64 = LoadDoubleWithHoleCheck(elements, index) otherwise IfHole;
|
||||
const e: float64 =
|
||||
LoadDoubleWithHoleCheck(elements, index) otherwise IfHole;
|
||||
return AllocateHeapNumberWithValue(e);
|
||||
}
|
||||
label Unexpected {
|
||||
@ -2706,12 +2707,12 @@ struct FastJSArrayWitness {
|
||||
MoveElements(dst: intptr, src: intptr, length: intptr) {
|
||||
assert(this.arrayIsPushable);
|
||||
if (this.hasDoubles) {
|
||||
let elements: FixedDoubleArray =
|
||||
const elements: FixedDoubleArray =
|
||||
Cast<FixedDoubleArray>(this.unstable.elements)
|
||||
otherwise unreachable;
|
||||
TorqueMoveElements(elements, dst, src, length);
|
||||
} else {
|
||||
let elements: FixedArray = Cast<FixedArray>(this.unstable.elements)
|
||||
const elements: FixedArray = Cast<FixedArray>(this.unstable.elements)
|
||||
otherwise unreachable;
|
||||
if (this.hasSmis) {
|
||||
TorqueMoveElementsSmi(elements, dst, src, length);
|
||||
@ -2730,7 +2731,7 @@ struct FastJSArrayWitness {
|
||||
}
|
||||
|
||||
macro NewFastJSArrayWitness(array: FastJSArray): FastJSArrayWitness {
|
||||
let kind = array.map.elements_kind;
|
||||
const kind = array.map.elements_kind;
|
||||
return FastJSArrayWitness{
|
||||
stable: array,
|
||||
unstable: array,
|
||||
@ -2782,7 +2783,7 @@ macro NumberIsNaN(number: Number): bool {
|
||||
return false;
|
||||
}
|
||||
case (hn: HeapNumber): {
|
||||
let value: float64 = Convert<float64>(hn);
|
||||
const value: float64 = Convert<float64>(hn);
|
||||
return value != value;
|
||||
}
|
||||
}
|
||||
@ -2806,7 +2807,7 @@ transitioning macro ToIndex(input: Object, context: Context): Number
|
||||
return 0;
|
||||
}
|
||||
|
||||
let value: Number = ToInteger_Inline(context, input, kTruncateMinusZero);
|
||||
const value: Number = ToInteger_Inline(context, input, kTruncateMinusZero);
|
||||
if (value < 0 || value > kMaxSafeInteger) {
|
||||
goto RangeError;
|
||||
}
|
||||
@ -2928,7 +2929,7 @@ namespace runtime {
|
||||
transitioning builtin FastCreateDataProperty(implicit context: Context)(
|
||||
receiver: JSReceiver, key: Object, value: Object): Object {
|
||||
try {
|
||||
let array = Cast<FastJSArray>(receiver) otherwise Slow;
|
||||
const array = Cast<FastJSArray>(receiver) otherwise Slow;
|
||||
const index: Smi = Cast<Smi>(key) otherwise goto Slow;
|
||||
if (index < 0 || index > array.length) goto Slow;
|
||||
array::EnsureWriteableFastElements(array);
|
||||
|
@ -67,7 +67,7 @@ namespace bigint {
|
||||
if (length > kBigIntMaxLength) {
|
||||
ThrowRangeError(kBigIntTooBig);
|
||||
}
|
||||
let result: MutableBigInt = AllocateBigInt(length);
|
||||
const result: MutableBigInt = AllocateBigInt(length);
|
||||
|
||||
WriteBigIntSignAndLength(result, sign, length);
|
||||
return result;
|
||||
@ -93,7 +93,7 @@ namespace bigint {
|
||||
return resultSign == xsign ? x : BigIntUnaryMinus(x);
|
||||
}
|
||||
|
||||
let result = AllocateEmptyBigInt(resultSign, xlength);
|
||||
const result = AllocateEmptyBigInt(resultSign, xlength);
|
||||
CppAbsoluteSubAndCanonicalize(result, x, y);
|
||||
return Convert<BigInt>(result);
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ namespace data_view {
|
||||
// ES6 section 24.2.4.1 get DataView.prototype.buffer
|
||||
javascript builtin DataViewPrototypeGetBuffer(
|
||||
context: Context, receiver: Object, ...arguments): JSArrayBuffer {
|
||||
let dataView: JSDataView =
|
||||
const dataView: JSDataView =
|
||||
ValidateDataView(context, receiver, 'get DataView.prototype.buffer');
|
||||
return dataView.buffer;
|
||||
}
|
||||
@ -83,7 +83,7 @@ namespace data_view {
|
||||
// ES6 section 24.2.4.2 get DataView.prototype.byteLength
|
||||
javascript builtin DataViewPrototypeGetByteLength(
|
||||
context: Context, receiver: Object, ...arguments): Number {
|
||||
let dataView: JSDataView = ValidateDataView(
|
||||
const dataView: JSDataView = ValidateDataView(
|
||||
context, receiver, 'get DataView.prototype.byte_length');
|
||||
if (WasNeutered(dataView)) {
|
||||
// TODO(bmeurer): According to the ES6 spec, we should throw a TypeError
|
||||
@ -96,7 +96,7 @@ namespace data_view {
|
||||
// ES6 section 24.2.4.3 get DataView.prototype.byteOffset
|
||||
javascript builtin DataViewPrototypeGetByteOffset(
|
||||
context: Context, receiver: Object, ...arguments): Number {
|
||||
let dataView: JSDataView = ValidateDataView(
|
||||
const dataView: JSDataView = ValidateDataView(
|
||||
context, receiver, 'get DataView.prototype.byte_offset');
|
||||
if (WasNeutered(dataView)) {
|
||||
// TODO(bmeurer): According to the ES6 spec, we should throw a TypeError
|
||||
@ -128,7 +128,7 @@ namespace data_view {
|
||||
macro LoadDataView16(
|
||||
buffer: JSArrayBuffer, offset: uintptr, requestedLittleEndian: bool,
|
||||
signed: constexpr bool): Number {
|
||||
let dataPointer: RawPtr = buffer.backing_store;
|
||||
const dataPointer: RawPtr = buffer.backing_store;
|
||||
|
||||
let b0: int32;
|
||||
let b1: int32;
|
||||
@ -155,12 +155,12 @@ namespace data_view {
|
||||
macro LoadDataView32(
|
||||
buffer: JSArrayBuffer, offset: uintptr, requestedLittleEndian: bool,
|
||||
kind: constexpr ElementsKind): Number {
|
||||
let dataPointer: RawPtr = buffer.backing_store;
|
||||
const dataPointer: RawPtr = buffer.backing_store;
|
||||
|
||||
let b0: uint32 = LoadUint8(dataPointer, offset);
|
||||
let b1: uint32 = LoadUint8(dataPointer, offset + 1);
|
||||
let b2: uint32 = LoadUint8(dataPointer, offset + 2);
|
||||
let b3: uint32 = LoadUint8(dataPointer, offset + 3);
|
||||
const b0: uint32 = LoadUint8(dataPointer, offset);
|
||||
const b1: uint32 = LoadUint8(dataPointer, offset + 1);
|
||||
const b2: uint32 = LoadUint8(dataPointer, offset + 2);
|
||||
const b3: uint32 = LoadUint8(dataPointer, offset + 3);
|
||||
let result: uint32;
|
||||
|
||||
if (requestedLittleEndian) {
|
||||
@ -174,7 +174,7 @@ namespace data_view {
|
||||
} else if constexpr (kind == UINT32_ELEMENTS) {
|
||||
return Convert<Number>(result);
|
||||
} else if constexpr (kind == FLOAT32_ELEMENTS) {
|
||||
let floatRes: float64 = Convert<float64>(BitcastInt32ToFloat32(result));
|
||||
const floatRes: float64 = Convert<float64>(BitcastInt32ToFloat32(result));
|
||||
return Convert<Number>(floatRes);
|
||||
} else {
|
||||
unreachable;
|
||||
@ -184,16 +184,16 @@ namespace data_view {
|
||||
macro LoadDataViewFloat64(
|
||||
buffer: JSArrayBuffer, offset: uintptr,
|
||||
requestedLittleEndian: bool): Number {
|
||||
let dataPointer: RawPtr = buffer.backing_store;
|
||||
const dataPointer: RawPtr = buffer.backing_store;
|
||||
|
||||
let b0: uint32 = LoadUint8(dataPointer, offset);
|
||||
let b1: uint32 = LoadUint8(dataPointer, offset + 1);
|
||||
let b2: uint32 = LoadUint8(dataPointer, offset + 2);
|
||||
let b3: uint32 = LoadUint8(dataPointer, offset + 3);
|
||||
let b4: uint32 = LoadUint8(dataPointer, offset + 4);
|
||||
let b5: uint32 = LoadUint8(dataPointer, offset + 5);
|
||||
let b6: uint32 = LoadUint8(dataPointer, offset + 6);
|
||||
let b7: uint32 = LoadUint8(dataPointer, offset + 7);
|
||||
const b0: uint32 = LoadUint8(dataPointer, offset);
|
||||
const b1: uint32 = LoadUint8(dataPointer, offset + 1);
|
||||
const b2: uint32 = LoadUint8(dataPointer, offset + 2);
|
||||
const b3: uint32 = LoadUint8(dataPointer, offset + 3);
|
||||
const b4: uint32 = LoadUint8(dataPointer, offset + 4);
|
||||
const b5: uint32 = LoadUint8(dataPointer, offset + 5);
|
||||
const b6: uint32 = LoadUint8(dataPointer, offset + 6);
|
||||
const b7: uint32 = LoadUint8(dataPointer, offset + 7);
|
||||
let lowWord: uint32;
|
||||
let highWord: uint32;
|
||||
|
||||
@ -225,8 +225,8 @@ namespace data_view {
|
||||
}
|
||||
|
||||
let sign: uint32 = bigint::kPositiveSign;
|
||||
let highPart: intptr = Signed(Convert<uintptr>(highWord));
|
||||
let lowPart: intptr = Signed(Convert<uintptr>(lowWord));
|
||||
const highPart: intptr = Signed(Convert<uintptr>(highWord));
|
||||
const lowPart: intptr = Signed(Convert<uintptr>(lowWord));
|
||||
let rawValue: intptr = (highPart << 32) + lowPart;
|
||||
|
||||
if constexpr (signed) {
|
||||
@ -238,7 +238,7 @@ namespace data_view {
|
||||
}
|
||||
|
||||
// Allocate the BigInt and store the absolute value.
|
||||
let result: MutableBigInt =
|
||||
const result: MutableBigInt =
|
||||
bigint::AllocateEmptyBigInt(sign, kOneDigitBigInt);
|
||||
bigint::StoreBigIntDigit(result, 0, Unsigned(rawValue));
|
||||
return Convert<BigInt>(result);
|
||||
@ -326,16 +326,16 @@ namespace data_view {
|
||||
macro LoadDataViewBigInt(implicit context: Context)(
|
||||
buffer: JSArrayBuffer, offset: uintptr, requestedLittleEndian: bool,
|
||||
signed: constexpr bool): BigInt {
|
||||
let dataPointer: RawPtr = buffer.backing_store;
|
||||
const dataPointer: RawPtr = buffer.backing_store;
|
||||
|
||||
let b0: uint32 = LoadUint8(dataPointer, offset);
|
||||
let b1: uint32 = LoadUint8(dataPointer, offset + 1);
|
||||
let b2: uint32 = LoadUint8(dataPointer, offset + 2);
|
||||
let b3: uint32 = LoadUint8(dataPointer, offset + 3);
|
||||
let b4: uint32 = LoadUint8(dataPointer, offset + 4);
|
||||
let b5: uint32 = LoadUint8(dataPointer, offset + 5);
|
||||
let b6: uint32 = LoadUint8(dataPointer, offset + 6);
|
||||
let b7: uint32 = LoadUint8(dataPointer, offset + 7);
|
||||
const b0: uint32 = LoadUint8(dataPointer, offset);
|
||||
const b1: uint32 = LoadUint8(dataPointer, offset + 1);
|
||||
const b2: uint32 = LoadUint8(dataPointer, offset + 2);
|
||||
const b3: uint32 = LoadUint8(dataPointer, offset + 3);
|
||||
const b4: uint32 = LoadUint8(dataPointer, offset + 4);
|
||||
const b5: uint32 = LoadUint8(dataPointer, offset + 5);
|
||||
const b6: uint32 = LoadUint8(dataPointer, offset + 6);
|
||||
const b7: uint32 = LoadUint8(dataPointer, offset + 7);
|
||||
let lowWord: uint32;
|
||||
let highWord: uint32;
|
||||
|
||||
@ -358,7 +358,7 @@ namespace data_view {
|
||||
transitioning macro DataViewGet(
|
||||
context: Context, receiver: Object, offset: Object,
|
||||
requestedLittleEndian: Object, kind: constexpr ElementsKind): Numeric {
|
||||
let dataView: JSDataView =
|
||||
const dataView: JSDataView =
|
||||
ValidateDataView(context, receiver, MakeDataViewGetterNameString(kind));
|
||||
|
||||
let getIndex: Number;
|
||||
@ -369,25 +369,25 @@ namespace data_view {
|
||||
ThrowRangeError(kInvalidDataViewAccessorOffset);
|
||||
}
|
||||
|
||||
let littleEndian: bool = ToBoolean(requestedLittleEndian);
|
||||
let buffer: JSArrayBuffer = dataView.buffer;
|
||||
const littleEndian: bool = ToBoolean(requestedLittleEndian);
|
||||
const buffer: JSArrayBuffer = dataView.buffer;
|
||||
|
||||
if (IsDetachedBuffer(buffer)) {
|
||||
ThrowTypeError(kDetachedOperation, MakeDataViewGetterNameString(kind));
|
||||
}
|
||||
|
||||
let getIndexFloat: float64 = Convert<float64>(getIndex);
|
||||
let getIndexWord: uintptr = Convert<uintptr>(getIndexFloat);
|
||||
const getIndexFloat: float64 = Convert<float64>(getIndex);
|
||||
const getIndexWord: uintptr = Convert<uintptr>(getIndexFloat);
|
||||
|
||||
let viewOffsetWord: uintptr = dataView.byte_offset;
|
||||
let viewSizeFloat: float64 = Convert<float64>(dataView.byte_length);
|
||||
let elementSizeFloat: float64 = DataViewElementSize(kind);
|
||||
const viewOffsetWord: uintptr = dataView.byte_offset;
|
||||
const viewSizeFloat: float64 = Convert<float64>(dataView.byte_length);
|
||||
const elementSizeFloat: float64 = DataViewElementSize(kind);
|
||||
|
||||
if (getIndexFloat + elementSizeFloat > viewSizeFloat) {
|
||||
ThrowRangeError(kInvalidDataViewAccessorOffset);
|
||||
}
|
||||
|
||||
let bufferIndex: uintptr = getIndexWord + viewOffsetWord;
|
||||
const bufferIndex: uintptr = getIndexWord + viewOffsetWord;
|
||||
|
||||
if constexpr (kind == UINT8_ELEMENTS) {
|
||||
return LoadDataView8(buffer, bufferIndex, false);
|
||||
@ -416,20 +416,20 @@ namespace data_view {
|
||||
|
||||
transitioning javascript builtin DataViewPrototypeGetUint8(
|
||||
context: Context, receiver: Object, ...arguments): Object {
|
||||
let offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
const offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
return DataViewGet(context, receiver, offset, Undefined, UINT8_ELEMENTS);
|
||||
}
|
||||
|
||||
transitioning javascript builtin DataViewPrototypeGetInt8(
|
||||
context: Context, receiver: Object, ...arguments): Object {
|
||||
let offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
const offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
return DataViewGet(context, receiver, offset, Undefined, INT8_ELEMENTS);
|
||||
}
|
||||
|
||||
transitioning javascript builtin DataViewPrototypeGetUint16(
|
||||
context: Context, receiver: Object, ...arguments): Object {
|
||||
let offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
let isLittleEndian: Object =
|
||||
const offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
const isLittleEndian: Object =
|
||||
arguments.length > 1 ? arguments[1] : Undefined;
|
||||
return DataViewGet(
|
||||
context, receiver, offset, isLittleEndian, UINT16_ELEMENTS);
|
||||
@ -437,8 +437,8 @@ namespace data_view {
|
||||
|
||||
transitioning javascript builtin DataViewPrototypeGetInt16(
|
||||
context: Context, receiver: Object, ...arguments): Object {
|
||||
let offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
let isLittleEndian: Object =
|
||||
const offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
const isLittleEndian: Object =
|
||||
arguments.length > 1 ? arguments[1] : Undefined;
|
||||
return DataViewGet(
|
||||
context, receiver, offset, isLittleEndian, INT16_ELEMENTS);
|
||||
@ -446,8 +446,8 @@ namespace data_view {
|
||||
|
||||
transitioning javascript builtin DataViewPrototypeGetUint32(
|
||||
context: Context, receiver: Object, ...arguments): Object {
|
||||
let offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
let isLittleEndian: Object =
|
||||
const offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
const isLittleEndian: Object =
|
||||
arguments.length > 1 ? arguments[1] : Undefined;
|
||||
return DataViewGet(
|
||||
context, receiver, offset, isLittleEndian, UINT32_ELEMENTS);
|
||||
@ -455,8 +455,8 @@ namespace data_view {
|
||||
|
||||
transitioning javascript builtin DataViewPrototypeGetInt32(
|
||||
context: Context, receiver: Object, ...arguments): Object {
|
||||
let offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
let isLittleEndian: Object =
|
||||
const offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
const isLittleEndian: Object =
|
||||
arguments.length > 1 ? arguments[1] : Undefined;
|
||||
return DataViewGet(
|
||||
context, receiver, offset, isLittleEndian, INT32_ELEMENTS);
|
||||
@ -464,8 +464,8 @@ namespace data_view {
|
||||
|
||||
transitioning javascript builtin DataViewPrototypeGetFloat32(
|
||||
context: Context, receiver: Object, ...arguments): Object {
|
||||
let offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
let isLittleEndian: Object =
|
||||
const offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
const isLittleEndian: Object =
|
||||
arguments.length > 1 ? arguments[1] : Undefined;
|
||||
return DataViewGet(
|
||||
context, receiver, offset, isLittleEndian, FLOAT32_ELEMENTS);
|
||||
@ -473,8 +473,8 @@ namespace data_view {
|
||||
|
||||
transitioning javascript builtin DataViewPrototypeGetFloat64(
|
||||
context: Context, receiver: Object, ...arguments): Object {
|
||||
let offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
let isLittleEndian: Object =
|
||||
const offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
const isLittleEndian: Object =
|
||||
arguments.length > 1 ? arguments[1] : Undefined;
|
||||
return DataViewGet(
|
||||
context, receiver, offset, isLittleEndian, FLOAT64_ELEMENTS);
|
||||
@ -482,8 +482,8 @@ namespace data_view {
|
||||
|
||||
transitioning javascript builtin DataViewPrototypeGetBigUint64(
|
||||
context: Context, receiver: Object, ...arguments): Object {
|
||||
let offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
let isLittleEndian: Object =
|
||||
const offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
const isLittleEndian: Object =
|
||||
arguments.length > 1 ? arguments[1] : Undefined;
|
||||
return DataViewGet(
|
||||
context, receiver, offset, isLittleEndian, BIGUINT64_ELEMENTS);
|
||||
@ -491,8 +491,8 @@ namespace data_view {
|
||||
|
||||
transitioning javascript builtin DataViewPrototypeGetBigInt64(
|
||||
context: Context, receiver: Object, ...arguments): Object {
|
||||
let offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
let isLittleEndian: Object =
|
||||
const offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
const isLittleEndian: Object =
|
||||
arguments.length > 1 ? arguments[1] : Undefined;
|
||||
return DataViewGet(
|
||||
context, receiver, offset, isLittleEndian, BIGINT64_ELEMENTS);
|
||||
@ -512,10 +512,10 @@ namespace data_view {
|
||||
macro StoreDataView16(
|
||||
buffer: JSArrayBuffer, offset: uintptr, value: uint32,
|
||||
requestedLittleEndian: bool) {
|
||||
let dataPointer: RawPtr = buffer.backing_store;
|
||||
const dataPointer: RawPtr = buffer.backing_store;
|
||||
|
||||
let b0: uint32 = value & 0xFF;
|
||||
let b1: uint32 = (value >>> 8) & 0xFF;
|
||||
const b0: uint32 = value & 0xFF;
|
||||
const b1: uint32 = (value >>> 8) & 0xFF;
|
||||
|
||||
if (requestedLittleEndian) {
|
||||
StoreWord8(dataPointer, offset, b0);
|
||||
@ -529,12 +529,12 @@ namespace data_view {
|
||||
macro StoreDataView32(
|
||||
buffer: JSArrayBuffer, offset: uintptr, value: uint32,
|
||||
requestedLittleEndian: bool) {
|
||||
let dataPointer: RawPtr = buffer.backing_store;
|
||||
const dataPointer: RawPtr = buffer.backing_store;
|
||||
|
||||
let b0: uint32 = value & 0xFF;
|
||||
let b1: uint32 = (value >>> 8) & 0xFF;
|
||||
let b2: uint32 = (value >>> 16) & 0xFF;
|
||||
let b3: uint32 = value >>> 24; // We don't need to mask here.
|
||||
const b0: uint32 = value & 0xFF;
|
||||
const b1: uint32 = (value >>> 8) & 0xFF;
|
||||
const b2: uint32 = (value >>> 16) & 0xFF;
|
||||
const b3: uint32 = value >>> 24; // We don't need to mask here.
|
||||
|
||||
if (requestedLittleEndian) {
|
||||
StoreWord8(dataPointer, offset, b0);
|
||||
@ -552,17 +552,17 @@ namespace data_view {
|
||||
macro StoreDataView64(
|
||||
buffer: JSArrayBuffer, offset: uintptr, lowWord: uint32, highWord: uint32,
|
||||
requestedLittleEndian: bool) {
|
||||
let dataPointer: RawPtr = buffer.backing_store;
|
||||
const dataPointer: RawPtr = buffer.backing_store;
|
||||
|
||||
let b0: uint32 = lowWord & 0xFF;
|
||||
let b1: uint32 = (lowWord >>> 8) & 0xFF;
|
||||
let b2: uint32 = (lowWord >>> 16) & 0xFF;
|
||||
let b3: uint32 = lowWord >>> 24;
|
||||
const b0: uint32 = lowWord & 0xFF;
|
||||
const b1: uint32 = (lowWord >>> 8) & 0xFF;
|
||||
const b2: uint32 = (lowWord >>> 16) & 0xFF;
|
||||
const b3: uint32 = lowWord >>> 24;
|
||||
|
||||
let b4: uint32 = highWord & 0xFF;
|
||||
let b5: uint32 = (highWord >>> 8) & 0xFF;
|
||||
let b6: uint32 = (highWord >>> 16) & 0xFF;
|
||||
let b7: uint32 = highWord >>> 24;
|
||||
const b4: uint32 = highWord & 0xFF;
|
||||
const b5: uint32 = (highWord >>> 8) & 0xFF;
|
||||
const b6: uint32 = (highWord >>> 16) & 0xFF;
|
||||
const b7: uint32 = highWord >>> 24;
|
||||
|
||||
if (requestedLittleEndian) {
|
||||
StoreWord8(dataPointer, offset, b0);
|
||||
@ -596,8 +596,8 @@ namespace data_view {
|
||||
macro StoreDataViewBigInt(
|
||||
buffer: JSArrayBuffer, offset: uintptr, bigIntValue: BigInt,
|
||||
requestedLittleEndian: bool) {
|
||||
let length: uint32 = DataViewDecodeBigIntLength(bigIntValue);
|
||||
let sign: uint32 = DataViewDecodeBigIntSign(bigIntValue);
|
||||
const length: uint32 = DataViewDecodeBigIntLength(bigIntValue);
|
||||
const sign: uint32 = DataViewDecodeBigIntSign(bigIntValue);
|
||||
|
||||
// The 32-bit words that will hold the BigInt's value in
|
||||
// two's complement representation.
|
||||
@ -608,7 +608,7 @@ namespace data_view {
|
||||
if (length != 0) {
|
||||
if constexpr (Is64()) {
|
||||
// There is always exactly 1 BigInt digit to load in this case.
|
||||
let value: uintptr = bigint::LoadBigIntDigit(bigIntValue, 0);
|
||||
const value: uintptr = bigint::LoadBigIntDigit(bigIntValue, 0);
|
||||
lowWord = Convert<uint32>(value); // Truncates value to 32 bits.
|
||||
highWord = Convert<uint32>(value >>> 32);
|
||||
} else { // There might be either 1 or 2 BigInt digits we need to load.
|
||||
@ -633,7 +633,7 @@ namespace data_view {
|
||||
transitioning macro DataViewSet(
|
||||
context: Context, receiver: Object, offset: Object, value: Object,
|
||||
requestedLittleEndian: Object, kind: constexpr ElementsKind): Object {
|
||||
let dataView: JSDataView =
|
||||
const dataView: JSDataView =
|
||||
ValidateDataView(context, receiver, MakeDataViewSetterNameString(kind));
|
||||
|
||||
let getIndex: Number;
|
||||
@ -644,52 +644,52 @@ namespace data_view {
|
||||
ThrowRangeError(kInvalidDataViewAccessorOffset);
|
||||
}
|
||||
|
||||
let littleEndian: bool = ToBoolean(requestedLittleEndian);
|
||||
let buffer: JSArrayBuffer = dataView.buffer;
|
||||
const littleEndian: bool = ToBoolean(requestedLittleEndian);
|
||||
const buffer: JSArrayBuffer = dataView.buffer;
|
||||
|
||||
// According to ES6 section 24.2.1.2 SetViewValue, we must perform
|
||||
// the conversion before doing the bounds check.
|
||||
if constexpr (kind == BIGUINT64_ELEMENTS || kind == BIGINT64_ELEMENTS) {
|
||||
let bigIntValue: BigInt = ToBigInt(context, value);
|
||||
const bigIntValue: BigInt = ToBigInt(context, value);
|
||||
|
||||
if (IsDetachedBuffer(buffer)) {
|
||||
ThrowTypeError(kDetachedOperation, MakeDataViewSetterNameString(kind));
|
||||
}
|
||||
|
||||
let getIndexFloat: float64 = Convert<float64>(getIndex);
|
||||
let getIndexWord: uintptr = Convert<uintptr>(getIndexFloat);
|
||||
const getIndexFloat: float64 = Convert<float64>(getIndex);
|
||||
const getIndexWord: uintptr = Convert<uintptr>(getIndexFloat);
|
||||
|
||||
let viewOffsetWord: uintptr = dataView.byte_offset;
|
||||
let viewSizeFloat: float64 = Convert<float64>(dataView.byte_length);
|
||||
let elementSizeFloat: float64 = DataViewElementSize(kind);
|
||||
const viewOffsetWord: uintptr = dataView.byte_offset;
|
||||
const viewSizeFloat: float64 = Convert<float64>(dataView.byte_length);
|
||||
const elementSizeFloat: float64 = DataViewElementSize(kind);
|
||||
|
||||
if (getIndexFloat + elementSizeFloat > viewSizeFloat) {
|
||||
ThrowRangeError(kInvalidDataViewAccessorOffset);
|
||||
}
|
||||
|
||||
let bufferIndex: uintptr = getIndexWord + viewOffsetWord;
|
||||
const bufferIndex: uintptr = getIndexWord + viewOffsetWord;
|
||||
StoreDataViewBigInt(buffer, bufferIndex, bigIntValue, littleEndian);
|
||||
} else {
|
||||
let numValue: Number = ToNumber(context, value);
|
||||
const numValue: Number = ToNumber(context, value);
|
||||
|
||||
if (IsDetachedBuffer(buffer)) {
|
||||
ThrowTypeError(kDetachedOperation, MakeDataViewSetterNameString(kind));
|
||||
}
|
||||
|
||||
let getIndexFloat: float64 = Convert<float64>(getIndex);
|
||||
let getIndexWord: uintptr = Convert<uintptr>(getIndexFloat);
|
||||
const getIndexFloat: float64 = Convert<float64>(getIndex);
|
||||
const getIndexWord: uintptr = Convert<uintptr>(getIndexFloat);
|
||||
|
||||
let viewOffsetWord: uintptr = dataView.byte_offset;
|
||||
let viewSizeFloat: float64 = Convert<float64>(dataView.byte_length);
|
||||
let elementSizeFloat: float64 = DataViewElementSize(kind);
|
||||
const viewOffsetWord: uintptr = dataView.byte_offset;
|
||||
const viewSizeFloat: float64 = Convert<float64>(dataView.byte_length);
|
||||
const elementSizeFloat: float64 = DataViewElementSize(kind);
|
||||
|
||||
if (getIndexFloat + elementSizeFloat > viewSizeFloat) {
|
||||
ThrowRangeError(kInvalidDataViewAccessorOffset);
|
||||
}
|
||||
|
||||
let bufferIndex: uintptr = getIndexWord + viewOffsetWord;
|
||||
const bufferIndex: uintptr = getIndexWord + viewOffsetWord;
|
||||
|
||||
let doubleValue: float64 = ChangeNumberToFloat64(numValue);
|
||||
const doubleValue: float64 = ChangeNumberToFloat64(numValue);
|
||||
|
||||
if constexpr (kind == UINT8_ELEMENTS || kind == INT8_ELEMENTS) {
|
||||
StoreDataView8(
|
||||
@ -703,13 +703,13 @@ namespace data_view {
|
||||
buffer, bufferIndex, TruncateFloat64ToWord32(doubleValue),
|
||||
littleEndian);
|
||||
} else if constexpr (kind == FLOAT32_ELEMENTS) {
|
||||
let floatValue: float32 = TruncateFloat64ToFloat32(doubleValue);
|
||||
const floatValue: float32 = TruncateFloat64ToFloat32(doubleValue);
|
||||
StoreDataView32(
|
||||
buffer, bufferIndex, BitcastFloat32ToInt32(floatValue),
|
||||
littleEndian);
|
||||
} else if constexpr (kind == FLOAT64_ELEMENTS) {
|
||||
let lowWord: uint32 = Float64ExtractLowWord32(doubleValue);
|
||||
let highWord: uint32 = Float64ExtractHighWord32(doubleValue);
|
||||
const lowWord: uint32 = Float64ExtractLowWord32(doubleValue);
|
||||
const highWord: uint32 = Float64ExtractHighWord32(doubleValue);
|
||||
StoreDataView64(buffer, bufferIndex, lowWord, highWord, littleEndian);
|
||||
}
|
||||
}
|
||||
@ -718,25 +718,25 @@ namespace data_view {
|
||||
|
||||
transitioning javascript builtin DataViewPrototypeSetUint8(
|
||||
context: Context, receiver: Object, ...arguments): Object {
|
||||
let offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
let value: Object = arguments.length > 1 ? arguments[1] : Undefined;
|
||||
const offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
const value: Object = arguments.length > 1 ? arguments[1] : Undefined;
|
||||
return DataViewSet(
|
||||
context, receiver, offset, value, Undefined, UINT8_ELEMENTS);
|
||||
}
|
||||
|
||||
transitioning javascript builtin DataViewPrototypeSetInt8(
|
||||
context: Context, receiver: Object, ...arguments): Object {
|
||||
let offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
let value: Object = arguments.length > 1 ? arguments[1] : Undefined;
|
||||
const offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
const value: Object = arguments.length > 1 ? arguments[1] : Undefined;
|
||||
return DataViewSet(
|
||||
context, receiver, offset, value, Undefined, INT8_ELEMENTS);
|
||||
}
|
||||
|
||||
transitioning javascript builtin DataViewPrototypeSetUint16(
|
||||
context: Context, receiver: Object, ...arguments): Object {
|
||||
let offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
let value: Object = arguments.length > 1 ? arguments[1] : Undefined;
|
||||
let isLittleEndian: Object =
|
||||
const offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
const value: Object = arguments.length > 1 ? arguments[1] : Undefined;
|
||||
const isLittleEndian: Object =
|
||||
arguments.length > 2 ? arguments[2] : Undefined;
|
||||
return DataViewSet(
|
||||
context, receiver, offset, value, isLittleEndian, UINT16_ELEMENTS);
|
||||
@ -744,9 +744,9 @@ namespace data_view {
|
||||
|
||||
transitioning javascript builtin DataViewPrototypeSetInt16(
|
||||
context: Context, receiver: Object, ...arguments): Object {
|
||||
let offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
let value: Object = arguments.length > 1 ? arguments[1] : Undefined;
|
||||
let isLittleEndian: Object =
|
||||
const offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
const value: Object = arguments.length > 1 ? arguments[1] : Undefined;
|
||||
const isLittleEndian: Object =
|
||||
arguments.length > 2 ? arguments[2] : Undefined;
|
||||
return DataViewSet(
|
||||
context, receiver, offset, value, isLittleEndian, INT16_ELEMENTS);
|
||||
@ -754,9 +754,9 @@ namespace data_view {
|
||||
|
||||
transitioning javascript builtin DataViewPrototypeSetUint32(
|
||||
context: Context, receiver: Object, ...arguments): Object {
|
||||
let offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
let value: Object = arguments.length > 1 ? arguments[1] : Undefined;
|
||||
let isLittleEndian: Object =
|
||||
const offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
const value: Object = arguments.length > 1 ? arguments[1] : Undefined;
|
||||
const isLittleEndian: Object =
|
||||
arguments.length > 2 ? arguments[2] : Undefined;
|
||||
return DataViewSet(
|
||||
context, receiver, offset, value, isLittleEndian, UINT32_ELEMENTS);
|
||||
@ -764,9 +764,9 @@ namespace data_view {
|
||||
|
||||
transitioning javascript builtin DataViewPrototypeSetInt32(
|
||||
context: Context, receiver: Object, ...arguments): Object {
|
||||
let offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
let value: Object = arguments.length > 1 ? arguments[1] : Undefined;
|
||||
let isLittleEndian: Object =
|
||||
const offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
const value: Object = arguments.length > 1 ? arguments[1] : Undefined;
|
||||
const isLittleEndian: Object =
|
||||
arguments.length > 2 ? arguments[2] : Undefined;
|
||||
return DataViewSet(
|
||||
context, receiver, offset, value, isLittleEndian, INT32_ELEMENTS);
|
||||
@ -774,9 +774,9 @@ namespace data_view {
|
||||
|
||||
transitioning javascript builtin DataViewPrototypeSetFloat32(
|
||||
context: Context, receiver: Object, ...arguments): Object {
|
||||
let offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
let value: Object = arguments.length > 1 ? arguments[1] : Undefined;
|
||||
let isLittleEndian: Object =
|
||||
const offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
const value: Object = arguments.length > 1 ? arguments[1] : Undefined;
|
||||
const isLittleEndian: Object =
|
||||
arguments.length > 2 ? arguments[2] : Undefined;
|
||||
return DataViewSet(
|
||||
context, receiver, offset, value, isLittleEndian, FLOAT32_ELEMENTS);
|
||||
@ -784,9 +784,9 @@ namespace data_view {
|
||||
|
||||
transitioning javascript builtin DataViewPrototypeSetFloat64(
|
||||
context: Context, receiver: Object, ...arguments): Object {
|
||||
let offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
let value: Object = arguments.length > 1 ? arguments[1] : Undefined;
|
||||
let isLittleEndian: Object =
|
||||
const offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
const value: Object = arguments.length > 1 ? arguments[1] : Undefined;
|
||||
const isLittleEndian: Object =
|
||||
arguments.length > 2 ? arguments[2] : Undefined;
|
||||
return DataViewSet(
|
||||
context, receiver, offset, value, isLittleEndian, FLOAT64_ELEMENTS);
|
||||
@ -794,9 +794,9 @@ namespace data_view {
|
||||
|
||||
transitioning javascript builtin DataViewPrototypeSetBigUint64(
|
||||
context: Context, receiver: Object, ...arguments): Object {
|
||||
let offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
let value: Object = arguments.length > 1 ? arguments[1] : Undefined;
|
||||
let isLittleEndian: Object =
|
||||
const offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
const value: Object = arguments.length > 1 ? arguments[1] : Undefined;
|
||||
const isLittleEndian: Object =
|
||||
arguments.length > 2 ? arguments[2] : Undefined;
|
||||
return DataViewSet(
|
||||
context, receiver, offset, value, isLittleEndian, BIGUINT64_ELEMENTS);
|
||||
@ -804,9 +804,9 @@ namespace data_view {
|
||||
|
||||
transitioning javascript builtin DataViewPrototypeSetBigInt64(
|
||||
context: Context, receiver: Object, ...arguments): Object {
|
||||
let offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
let value: Object = arguments.length > 1 ? arguments[1] : Undefined;
|
||||
let isLittleEndian: Object =
|
||||
const offset: Object = arguments.length > 0 ? arguments[0] : Undefined;
|
||||
const value: Object = arguments.length > 1 ? arguments[1] : Undefined;
|
||||
const isLittleEndian: Object =
|
||||
arguments.length > 2 ? arguments[2] : Undefined;
|
||||
return DataViewSet(
|
||||
context, receiver, offset, value, isLittleEndian, BIGINT64_ELEMENTS);
|
||||
|
@ -137,7 +137,7 @@ namespace regexp_replace {
|
||||
let result: String = kEmptyString;
|
||||
let lastMatchEnd: Smi = 0;
|
||||
let unicode: bool = false;
|
||||
let replaceLength: Smi = replaceString.length_smi;
|
||||
const replaceLength: Smi = replaceString.length_smi;
|
||||
const global: bool = regexp.global;
|
||||
|
||||
if (global) {
|
||||
|
@ -63,7 +63,7 @@ namespace string {
|
||||
const searchLength: Smi = searchStr.length_smi;
|
||||
|
||||
// 10. Let start be end - searchLength.
|
||||
let start = end - searchLength;
|
||||
const start = end - searchLength;
|
||||
|
||||
// 11. If start is less than 0, return false.
|
||||
if (start < 0) return False;
|
||||
|
@ -322,7 +322,7 @@ namespace typed_array {
|
||||
let loadfn: LoadFn;
|
||||
let storefn: StoreFn;
|
||||
|
||||
let elementsKind: ElementsKind = array.elements_kind;
|
||||
const elementsKind: ElementsKind = array.elements_kind;
|
||||
|
||||
if (IsElementsKindGreaterThan(elementsKind, UINT32_ELEMENTS)) {
|
||||
if (elementsKind == INT32_ELEMENTS) {
|
||||
|
@ -1830,7 +1830,7 @@ LocationReference ImplementationVisitor::GetLocationReference(
|
||||
return LocationReference::Temporary(
|
||||
(*value)->value, "constant value " + expr->name->value);
|
||||
}
|
||||
return LocationReference::VariableAccess((*value)->value);
|
||||
return LocationReference::VariableAccess((*value)->value, *value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1927,6 +1927,12 @@ void ImplementationVisitor::GenerateAssignToLocation(
|
||||
GenerateImplicitConvert(variable.type(), assignment_value);
|
||||
assembler().Poke(variable.stack_range(), converted_value.stack_range(),
|
||||
variable.type());
|
||||
|
||||
// Local variables are detected by the existence of a binding. Assignment
|
||||
// to local variables is recorded to support lint errors.
|
||||
if (reference.binding()) {
|
||||
(*reference.binding())->SetWritten();
|
||||
}
|
||||
} else if (reference.IsIndexedFieldAccess()) {
|
||||
ReportError("assigning a value directly to an indexed field isn't allowed");
|
||||
} else if (reference.IsHeapReference()) {
|
||||
|
@ -19,6 +19,10 @@ namespace v8 {
|
||||
namespace internal {
|
||||
namespace torque {
|
||||
|
||||
template <typename T>
|
||||
class Binding;
|
||||
struct LocalValue;
|
||||
|
||||
// LocationReference is the representation of an l-value, so a value that might
|
||||
// allow for assignment. For uniformity, this class can also represent
|
||||
// unassignable temporaries. Assignable values fall in two categories:
|
||||
@ -27,10 +31,13 @@ namespace torque {
|
||||
class LocationReference {
|
||||
public:
|
||||
// An assignable stack range.
|
||||
static LocationReference VariableAccess(VisitResult variable) {
|
||||
static LocationReference VariableAccess(
|
||||
VisitResult variable,
|
||||
base::Optional<Binding<LocalValue>*> binding = base::nullopt) {
|
||||
DCHECK(variable.IsOnStack());
|
||||
LocationReference result;
|
||||
result.variable_ = std::move(variable);
|
||||
result.binding_ = binding;
|
||||
return result;
|
||||
}
|
||||
// An unassignable value. {description} is only used for error messages.
|
||||
@ -146,6 +153,10 @@ class LocationReference {
|
||||
DCHECK(IsCallAccess());
|
||||
return *assign_function_;
|
||||
}
|
||||
base::Optional<Binding<LocalValue>*> binding() const {
|
||||
DCHECK(IsVariableAccess());
|
||||
return binding_;
|
||||
}
|
||||
|
||||
private:
|
||||
base::Optional<VisitResult> variable_;
|
||||
@ -156,6 +167,7 @@ class LocationReference {
|
||||
base::Optional<std::string> assign_function_;
|
||||
VisitResultVector call_arguments_;
|
||||
base::Optional<std::string> index_field_;
|
||||
base::Optional<Binding<LocalValue>*> binding_;
|
||||
|
||||
LocationReference() = default;
|
||||
};
|
||||
@ -198,7 +210,8 @@ class Binding : public T {
|
||||
manager_(manager),
|
||||
name_(name),
|
||||
previous_binding_(this),
|
||||
used_(false) {
|
||||
used_(false),
|
||||
written_(false) {
|
||||
std::swap(previous_binding_, manager_->current_bindings_[name]);
|
||||
}
|
||||
template <class... Args>
|
||||
@ -207,15 +220,23 @@ class Binding : public T {
|
||||
declaration_position_ = name->pos;
|
||||
}
|
||||
~Binding() {
|
||||
manager_->current_bindings_[name_] = previous_binding_;
|
||||
if (!used_ && name_.length() > 0 && name_[0] != '_') {
|
||||
if (!used_ && !SkipLintCheck()) {
|
||||
Lint(BindingTypeString(), "'", name_,
|
||||
"' is never used. Prefix with '_' if this is intentional.")
|
||||
.Position(declaration_position_);
|
||||
}
|
||||
|
||||
if (CheckWritten() && !written_ && !SkipLintCheck()) {
|
||||
Lint(BindingTypeString(), "'", name_,
|
||||
"' is never assigned to. Use 'const' instead of 'let'.")
|
||||
.Position(declaration_position_);
|
||||
}
|
||||
|
||||
manager_->current_bindings_[name_] = previous_binding_;
|
||||
}
|
||||
|
||||
std::string BindingTypeString() const { return ""; }
|
||||
std::string BindingTypeString() const;
|
||||
bool CheckWritten() const;
|
||||
|
||||
const std::string& name() const { return name_; }
|
||||
SourcePosition declaration_position() const { return declaration_position_; }
|
||||
@ -223,12 +244,18 @@ class Binding : public T {
|
||||
bool Used() const { return used_; }
|
||||
void SetUsed() { used_ = true; }
|
||||
|
||||
bool Written() const { return written_; }
|
||||
void SetWritten() { written_ = true; }
|
||||
|
||||
private:
|
||||
bool SkipLintCheck() const { return name_.length() > 0 && name_[0] == '_'; }
|
||||
|
||||
BindingsManager<T>* manager_;
|
||||
const std::string name_;
|
||||
base::Optional<Binding*> previous_binding_;
|
||||
SourcePosition declaration_position_ = CurrentSourcePosition::Get();
|
||||
bool used_;
|
||||
bool written_;
|
||||
DISALLOW_COPY_AND_ASSIGN(Binding);
|
||||
};
|
||||
|
||||
@ -296,9 +323,19 @@ inline std::string Binding<LocalValue>::BindingTypeString() const {
|
||||
return "Variable ";
|
||||
}
|
||||
template <>
|
||||
inline bool Binding<LocalValue>::CheckWritten() const {
|
||||
// Do the check only for non-const variables and non struct types.
|
||||
auto binding = *manager_->current_bindings_[name_];
|
||||
return !binding->is_const && !binding->value.type()->IsStructType();
|
||||
}
|
||||
template <>
|
||||
inline std::string Binding<LocalLabel>::BindingTypeString() const {
|
||||
return "Label ";
|
||||
}
|
||||
template <>
|
||||
inline bool Binding<LocalLabel>::CheckWritten() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct Arguments {
|
||||
VisitResultVector parameters;
|
||||
|
@ -126,8 +126,8 @@ namespace test {
|
||||
|
||||
@export
|
||||
macro TestPartiallyUnusedLabel(): Boolean {
|
||||
let r1: bool = CallLabelTestHelper4(true);
|
||||
let r2: bool = CallLabelTestHelper4(false);
|
||||
const r1: bool = CallLabelTestHelper4(true);
|
||||
const r2: bool = CallLabelTestHelper4(false);
|
||||
|
||||
if (r1 && !r2) {
|
||||
return True;
|
||||
@ -200,14 +200,15 @@ namespace test {
|
||||
|
||||
@export
|
||||
macro TestTernaryOperator(x: Smi): Smi {
|
||||
let b: bool = x < 0 ? true : false;
|
||||
const b: bool = x < 0 ? true : false;
|
||||
return b ? x - 10 : x + 100;
|
||||
}
|
||||
|
||||
@export
|
||||
macro TestFunctionPointerToGeneric(c: Context) {
|
||||
let fptr1: builtin(Context, Smi) => Object = GenericBuiltinTest<Smi>;
|
||||
let fptr2: builtin(Context, Object) => Object = GenericBuiltinTest<Object>;
|
||||
const fptr1: builtin(Context, Smi) => Object = GenericBuiltinTest<Smi>;
|
||||
const fptr2: builtin(Context, Object) => Object =
|
||||
GenericBuiltinTest<Object>;
|
||||
|
||||
check(fptr1(c, 0) == Null);
|
||||
check(fptr1(c, 1) == Null);
|
||||
@ -224,7 +225,7 @@ namespace test {
|
||||
@export
|
||||
macro TestUnsafeCast(implicit context: Context)(n: Number): Boolean {
|
||||
if (TaggedIsSmi(n)) {
|
||||
let m: Smi = UnsafeCast<Smi>(n);
|
||||
const m: Smi = UnsafeCast<Smi>(n);
|
||||
|
||||
check(TestHelperPlus1(context, m) == 11);
|
||||
return True;
|
||||
@ -246,7 +247,7 @@ namespace test {
|
||||
|
||||
@export
|
||||
macro TestMultilineAssert() {
|
||||
let someVeryLongVariableNameThatWillCauseLineBreaks: Smi = 5;
|
||||
const someVeryLongVariableNameThatWillCauseLineBreaks: Smi = 5;
|
||||
check(
|
||||
someVeryLongVariableNameThatWillCauseLineBreaks > 0 &&
|
||||
someVeryLongVariableNameThatWillCauseLineBreaks < 10);
|
||||
@ -313,7 +314,7 @@ namespace test {
|
||||
let a: TestStructA =
|
||||
TestStructA{indexes: UnsafeCast<FixedArray>(kEmptyFixedArray), i: 13, k: 5};
|
||||
let _b: TestStructA = a;
|
||||
let c: TestStructA = TestStruct2();
|
||||
const c: TestStructA = TestStruct2();
|
||||
a.i = TestStruct1(c);
|
||||
a.k = a.i;
|
||||
let d: TestStructB;
|
||||
@ -689,7 +690,7 @@ namespace test {
|
||||
|
||||
@export
|
||||
macro TestQualifiedAccess(implicit context: Context)() {
|
||||
let s: Smi = 0;
|
||||
const s: Smi = 0;
|
||||
check(!array::IsJSArray(s));
|
||||
}
|
||||
|
||||
@ -873,7 +874,7 @@ namespace test {
|
||||
|
||||
@export
|
||||
macro TestNewFixedArrayFromSpread(implicit context: Context)(): Object {
|
||||
const i = TestIterator{count: 5};
|
||||
let i = TestIterator{count: 5};
|
||||
return new FixedArray{map: kFixedArrayMap, length: 5, objects: ...i};
|
||||
}
|
||||
|
||||
|
@ -295,6 +295,25 @@ TEST(Torque, ImportNonExistentFile) {
|
||||
HasSubstr("File 'foo/bar.tq' not found."));
|
||||
}
|
||||
|
||||
TEST(Torque, LetShouldBeConstLintError) {
|
||||
ExpectFailingCompilation(R"(
|
||||
macro Foo(y: Smi): Smi {
|
||||
let x: Smi = y;
|
||||
return x;
|
||||
})",
|
||||
HasSubstr("Variable 'x' is never assigned to."));
|
||||
}
|
||||
|
||||
TEST(Torque, LetShouldBeConstIsSkippedForStructs) {
|
||||
ExpectSuccessfulCompilation(R"(
|
||||
struct Foo{ a: Smi; }
|
||||
macro Bar(x: Smi): Foo {
|
||||
let foo = Foo{a: x};
|
||||
return foo;
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
} // namespace torque
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
22
third_party/v8/builtins/array-sort.tq
vendored
22
third_party/v8/builtins/array-sort.tq
vendored
@ -144,7 +144,7 @@ namespace array {
|
||||
|
||||
try {
|
||||
GotoIfForceSlowPath() otherwise Slow;
|
||||
let a: FastJSArray = Cast<FastJSArray>(receiver) otherwise Slow;
|
||||
const a: FastJSArray = Cast<FastJSArray>(receiver) otherwise Slow;
|
||||
|
||||
// Copy copy-on-write (COW) arrays.
|
||||
array::EnsureWriteableFastElements(a);
|
||||
@ -477,7 +477,7 @@ namespace array {
|
||||
} else {
|
||||
let srcIdx: Smi = srcPos;
|
||||
let dstIdx: Smi = dstPos;
|
||||
let to: Smi = srcPos + length;
|
||||
const to: Smi = srcPos + length;
|
||||
|
||||
while (srcIdx < to) {
|
||||
target.objects[dstIdx++] = source.objects[srcIdx++];
|
||||
@ -566,7 +566,7 @@ namespace array {
|
||||
|
||||
const workArray = sortState.workArray;
|
||||
|
||||
let low: Smi = lowArg + 1;
|
||||
const low: Smi = lowArg + 1;
|
||||
if (low == high) return 1;
|
||||
|
||||
let runLength: Smi = 2;
|
||||
@ -631,7 +631,7 @@ namespace array {
|
||||
const pendingRuns: FixedArray = sortState.pendingRuns;
|
||||
let baseA: Smi = GetPendingRunBase(pendingRuns, i);
|
||||
let lengthA: Smi = GetPendingRunLength(pendingRuns, i);
|
||||
let baseB: Smi = GetPendingRunBase(pendingRuns, i + 1);
|
||||
const baseB: Smi = GetPendingRunBase(pendingRuns, i + 1);
|
||||
let lengthB: Smi = GetPendingRunLength(pendingRuns, i + 1);
|
||||
assert(lengthA > 0 && lengthB > 0);
|
||||
assert(baseA + lengthA == baseB);
|
||||
@ -710,7 +710,7 @@ namespace array {
|
||||
// a[base + hint + lastOfs] < key <= a[base + hint + offset].
|
||||
|
||||
// a[base + length - 1] is highest.
|
||||
let maxOfs: Smi = length - hint;
|
||||
const maxOfs: Smi = length - hint;
|
||||
while (offset < maxOfs) {
|
||||
const offsetElement = array.objects[base + hint + offset];
|
||||
order = sortState.Compare(offsetElement, key);
|
||||
@ -736,7 +736,7 @@ namespace array {
|
||||
assert(order >= 0);
|
||||
|
||||
// a[base + hint] is lowest.
|
||||
let maxOfs: Smi = hint + 1;
|
||||
const maxOfs: Smi = hint + 1;
|
||||
while (offset < maxOfs) {
|
||||
const offsetElement = array.objects[base + hint - offset];
|
||||
order = sortState.Compare(offsetElement, key);
|
||||
@ -807,7 +807,7 @@ namespace array {
|
||||
// a[base + hint - offset] <= key < a[base + hint - lastOfs].
|
||||
|
||||
// a[base + hint] is lowest.
|
||||
let maxOfs: Smi = hint + 1;
|
||||
const maxOfs: Smi = hint + 1;
|
||||
while (offset < maxOfs) {
|
||||
const offsetElement = array.objects[base + hint - offset];
|
||||
order = sortState.Compare(key, offsetElement);
|
||||
@ -832,7 +832,7 @@ namespace array {
|
||||
// a[base + hint + lastOfs] <= key < a[base + hint + offset].
|
||||
|
||||
// a[base + length - 1] is highest.
|
||||
let maxOfs: Smi = length - hint;
|
||||
const maxOfs: Smi = length - hint;
|
||||
while (offset < maxOfs) {
|
||||
const offsetElement = array.objects[base + hint + offset];
|
||||
order = sortState.Compare(key, offsetElement);
|
||||
@ -920,7 +920,7 @@ namespace array {
|
||||
while (Int32TrueConstant()) {
|
||||
assert(lengthA > 1 && lengthB > 0);
|
||||
|
||||
let order = sortState.Compare(
|
||||
const order = sortState.Compare(
|
||||
workArray.objects[cursorB], tempArray.objects[cursorTemp]);
|
||||
|
||||
if (order < 0) {
|
||||
@ -1052,7 +1052,7 @@ namespace array {
|
||||
while (Int32TrueConstant()) {
|
||||
assert(lengthA > 0 && lengthB > 1);
|
||||
|
||||
let order = sortState.Compare(
|
||||
const order = sortState.Compare(
|
||||
tempArray.objects[cursorTemp], workArray.objects[cursorA]);
|
||||
|
||||
if (order < 0) {
|
||||
@ -1222,7 +1222,7 @@ namespace array {
|
||||
// remains. This is used at the end of the mergesort.
|
||||
transitioning macro
|
||||
MergeForceCollapse(context: Context, sortState: SortState) {
|
||||
let pendingRuns: FixedArray = sortState.pendingRuns;
|
||||
const pendingRuns: FixedArray = sortState.pendingRuns;
|
||||
|
||||
// Reload the stack size becuase MergeAt might change it.
|
||||
while (GetPendingRunsSize(sortState) > 1) {
|
||||
|
Loading…
Reference in New Issue
Block a user