[Torque] Port some (Shared)ArrayBuffer APIs

Bug: v8:9891
Change-Id: I04a1eaedc1e3e012a4779671025c8b71d1c6a56e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2391909
Commit-Queue: Gus Caplan <snek@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69745}
This commit is contained in:
Gus Caplan 2020-09-08 09:15:52 -05:00 committed by Commit Bot
parent b45693010f
commit e091d5b2f5
5 changed files with 88 additions and 53 deletions

View File

@ -1122,6 +1122,7 @@ torque_files = [
"src/builtins/array-splice.tq",
"src/builtins/array-unshift.tq",
"src/builtins/array.tq",
"src/builtins/arraybuffer.tq",
"src/builtins/base.tq",
"src/builtins/bigint.tq",
"src/builtins/boolean.tq",

View File

@ -0,0 +1,66 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
namespace arraybuffer {
// #sec-get-arraybuffer.prototype.bytelength
transitioning javascript builtin ArrayBufferPrototypeGetByteLength(
js-implicit context: NativeContext, receiver: JSAny)(): Number {
// 1. Let O be the this value.
// 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
const o = Cast<JSArrayBuffer>(receiver) otherwise
ThrowTypeError(
MessageTemplate::kIncompatibleMethodReceiver,
'get ArrayBuffer.prototype.byteLength', receiver);
// 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
if (IsSharedArrayBuffer(o)) {
ThrowTypeError(
MessageTemplate::kIncompatibleMethodReceiver,
'get ArrayBuffer.prototype.byteLength', receiver);
}
// 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
// TODO(v8:4895): We don't actually throw here.
// 5. Let length be O.[[ArrayBufferByteLength]].
const length = o.byte_length;
// 6. Return length.
return Convert<Number>(length);
}
// #sec-get-sharedarraybuffer.prototype.bytelength
transitioning javascript builtin SharedArrayBufferPrototypeGetByteLength(
js-implicit context: NativeContext, receiver: JSAny)(): Number {
// 1. Let O be the this value.
// 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
const o = Cast<JSArrayBuffer>(receiver) otherwise
ThrowTypeError(
MessageTemplate::kIncompatibleMethodReceiver,
'get SharedArrayBuffer.prototype.byteLength', receiver);
// 3. If IsSharedArrayBuffer(O) is false, throw a TypeError exception.
if (!IsSharedArrayBuffer(o)) {
ThrowTypeError(
MessageTemplate::kIncompatibleMethodReceiver,
'get SharedArrayBuffer.prototype.byteLength', receiver);
}
// 4. Let length be O.[[ArrayBufferByteLength]].
const length = o.byte_length;
// 5. Return length.
return Convert<Number>(length);
}
// #sec-arraybuffer.isview
transitioning javascript builtin ArrayBufferIsView(arg: JSAny): Boolean {
// 1. If Type(arg) is not Object, return false.
// 2. If arg has a [[ViewedArrayBuffer]] internal slot, return true.
// 3. Return false.
typeswitch (arg) {
case (JSArrayBufferView): {
return True;
}
case (JSAny): {
return False;
}
}
}
} // namespace arraybuffer

View File

@ -105,35 +105,6 @@ BUILTIN(ArrayBufferConstructor_DoNotInitialize) {
InitializedFlag::kUninitialized);
}
// ES6 section 24.1.4.1 get ArrayBuffer.prototype.byteLength
BUILTIN(ArrayBufferPrototypeGetByteLength) {
const char* const kMethodName = "get ArrayBuffer.prototype.byteLength";
HandleScope scope(isolate);
CHECK_RECEIVER(JSArrayBuffer, array_buffer, kMethodName);
CHECK_SHARED(false, array_buffer, kMethodName);
// TODO(franzih): According to the ES6 spec, we should throw a TypeError
// here if the JSArrayBuffer is detached.
return *isolate->factory()->NewNumberFromSize(array_buffer->byte_length());
}
// ES7 sharedmem 6.3.4.1 get SharedArrayBuffer.prototype.byteLength
BUILTIN(SharedArrayBufferPrototypeGetByteLength) {
const char* const kMethodName = "get SharedArrayBuffer.prototype.byteLength";
HandleScope scope(isolate);
CHECK_RECEIVER(JSArrayBuffer, array_buffer,
"get SharedArrayBuffer.prototype.byteLength");
CHECK_SHARED(true, array_buffer, kMethodName);
return *isolate->factory()->NewNumberFromSize(array_buffer->byte_length());
}
// ES6 section 24.1.3.1 ArrayBuffer.isView ( arg )
BUILTIN(ArrayBufferIsView) {
SealHandleScope shs(isolate);
DCHECK_EQ(2, args.length());
Object arg = args[1];
return isolate->heap()->ToBoolean(arg.IsJSArrayBufferView());
}
static Object SliceHelper(BuiltinArguments args, Isolate* isolate,
const char* kMethodName, bool is_shared) {
HandleScope scope(isolate);

View File

@ -341,8 +341,6 @@ namespace internal {
/* ES #sec-arraybuffer-constructor */ \
CPP(ArrayBufferConstructor) \
CPP(ArrayBufferConstructor_DoNotInitialize) \
CPP(ArrayBufferPrototypeGetByteLength) \
CPP(ArrayBufferIsView) \
CPP(ArrayBufferPrototypeSlice) \
\
/* AsyncFunction */ \
@ -722,7 +720,6 @@ namespace internal {
TFS(SetOrSetIteratorToList, kSource) \
\
/* SharedArrayBuffer */ \
CPP(SharedArrayBufferPrototypeGetByteLength) \
CPP(SharedArrayBufferPrototypeSlice) \
TFJ(AtomicsLoad, 2, kReceiver, kArray, kIndex) \
TFJ(AtomicsStore, 3, kReceiver, kArray, kIndex, kValue) \

View File

@ -444,27 +444,27 @@ KNOWN_OBJECTS = {
("old_space", 0x02a61): "StringSplitCache",
("old_space", 0x02e69): "RegExpMultipleCache",
("old_space", 0x03271): "BuiltinsConstantsTable",
("old_space", 0x03645): "AsyncFunctionAwaitRejectSharedFun",
("old_space", 0x0366d): "AsyncFunctionAwaitResolveSharedFun",
("old_space", 0x03695): "AsyncGeneratorAwaitRejectSharedFun",
("old_space", 0x036bd): "AsyncGeneratorAwaitResolveSharedFun",
("old_space", 0x036e5): "AsyncGeneratorYieldResolveSharedFun",
("old_space", 0x0370d): "AsyncGeneratorReturnResolveSharedFun",
("old_space", 0x03735): "AsyncGeneratorReturnClosedRejectSharedFun",
("old_space", 0x0375d): "AsyncGeneratorReturnClosedResolveSharedFun",
("old_space", 0x03785): "AsyncIteratorValueUnwrapSharedFun",
("old_space", 0x037ad): "PromiseAllResolveElementSharedFun",
("old_space", 0x037d5): "PromiseAllSettledResolveElementSharedFun",
("old_space", 0x037fd): "PromiseAllSettledRejectElementSharedFun",
("old_space", 0x03825): "PromiseAnyRejectElementSharedFun",
("old_space", 0x0384d): "PromiseCapabilityDefaultRejectSharedFun",
("old_space", 0x03875): "PromiseCapabilityDefaultResolveSharedFun",
("old_space", 0x0389d): "PromiseCatchFinallySharedFun",
("old_space", 0x038c5): "PromiseGetCapabilitiesExecutorSharedFun",
("old_space", 0x038ed): "PromiseThenFinallySharedFun",
("old_space", 0x03915): "PromiseThrowerFinallySharedFun",
("old_space", 0x0393d): "PromiseValueThunkFinallySharedFun",
("old_space", 0x03965): "ProxyRevokeSharedFun",
("old_space", 0x0364d): "AsyncFunctionAwaitRejectSharedFun",
("old_space", 0x03675): "AsyncFunctionAwaitResolveSharedFun",
("old_space", 0x0369d): "AsyncGeneratorAwaitRejectSharedFun",
("old_space", 0x036c5): "AsyncGeneratorAwaitResolveSharedFun",
("old_space", 0x036ed): "AsyncGeneratorYieldResolveSharedFun",
("old_space", 0x03715): "AsyncGeneratorReturnResolveSharedFun",
("old_space", 0x0373d): "AsyncGeneratorReturnClosedRejectSharedFun",
("old_space", 0x03765): "AsyncGeneratorReturnClosedResolveSharedFun",
("old_space", 0x0378d): "AsyncIteratorValueUnwrapSharedFun",
("old_space", 0x037b5): "PromiseAllResolveElementSharedFun",
("old_space", 0x037dd): "PromiseAllSettledResolveElementSharedFun",
("old_space", 0x03805): "PromiseAllSettledRejectElementSharedFun",
("old_space", 0x0382d): "PromiseAnyRejectElementSharedFun",
("old_space", 0x03855): "PromiseCapabilityDefaultRejectSharedFun",
("old_space", 0x0387d): "PromiseCapabilityDefaultResolveSharedFun",
("old_space", 0x038a5): "PromiseCatchFinallySharedFun",
("old_space", 0x038cd): "PromiseGetCapabilitiesExecutorSharedFun",
("old_space", 0x038f5): "PromiseThenFinallySharedFun",
("old_space", 0x0391d): "PromiseThrowerFinallySharedFun",
("old_space", 0x03945): "PromiseValueThunkFinallySharedFun",
("old_space", 0x0396d): "ProxyRevokeSharedFun",
}
# Lower 32 bits of first page addresses for various heap spaces.