11cb0ef41Sopenharmony_ci// Copyright 2020 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_cinamespace arraybuffer { 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci// #sec-get-arraybuffer.prototype.bytelength 81cb0ef41Sopenharmony_citransitioning javascript builtin ArrayBufferPrototypeGetByteLength( 91cb0ef41Sopenharmony_ci js-implicit context: NativeContext, receiver: JSAny)(): Number { 101cb0ef41Sopenharmony_ci // 1. Let O be the this value. 111cb0ef41Sopenharmony_ci // 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). 121cb0ef41Sopenharmony_ci const functionName = 'get ArrayBuffer.prototype.byteLength'; 131cb0ef41Sopenharmony_ci const o = Cast<JSArrayBuffer>(receiver) otherwise 141cb0ef41Sopenharmony_ci ThrowTypeError( 151cb0ef41Sopenharmony_ci MessageTemplate::kIncompatibleMethodReceiver, functionName, receiver); 161cb0ef41Sopenharmony_ci // 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. 171cb0ef41Sopenharmony_ci if (IsSharedArrayBuffer(o)) { 181cb0ef41Sopenharmony_ci ThrowTypeError( 191cb0ef41Sopenharmony_ci MessageTemplate::kIncompatibleMethodReceiver, functionName, receiver); 201cb0ef41Sopenharmony_ci } 211cb0ef41Sopenharmony_ci // 4. Let length be O.[[ArrayBufferByteLength]]. 221cb0ef41Sopenharmony_ci const length = o.byte_length; 231cb0ef41Sopenharmony_ci // 5. Return length. 241cb0ef41Sopenharmony_ci return Convert<Number>(length); 251cb0ef41Sopenharmony_ci} 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci// #sec-get-arraybuffer.prototype.maxbytelength 281cb0ef41Sopenharmony_citransitioning javascript builtin ArrayBufferPrototypeGetMaxByteLength( 291cb0ef41Sopenharmony_ci js-implicit context: NativeContext, receiver: JSAny)(): Number { 301cb0ef41Sopenharmony_ci // 1. Let O be the this value. 311cb0ef41Sopenharmony_ci // 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). 321cb0ef41Sopenharmony_ci const functionName = 'get ArrayBuffer.prototype.maxByteLength'; 331cb0ef41Sopenharmony_ci const o = Cast<JSArrayBuffer>(receiver) otherwise 341cb0ef41Sopenharmony_ci ThrowTypeError( 351cb0ef41Sopenharmony_ci MessageTemplate::kIncompatibleMethodReceiver, functionName, receiver); 361cb0ef41Sopenharmony_ci // 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. 371cb0ef41Sopenharmony_ci if (IsSharedArrayBuffer(o)) { 381cb0ef41Sopenharmony_ci ThrowTypeError( 391cb0ef41Sopenharmony_ci MessageTemplate::kIncompatibleMethodReceiver, functionName, receiver); 401cb0ef41Sopenharmony_ci } 411cb0ef41Sopenharmony_ci // 4. If IsDetachedBuffer(O) is true, return 0_F. 421cb0ef41Sopenharmony_ci if (IsDetachedBuffer(o)) { 431cb0ef41Sopenharmony_ci return 0; 441cb0ef41Sopenharmony_ci } 451cb0ef41Sopenharmony_ci // 5. If IsResizableArrayBuffer(O) is true, then 461cb0ef41Sopenharmony_ci // a. Let length be O.[[ArrayBufferMaxByteLength]]. 471cb0ef41Sopenharmony_ci // 6. Else, 481cb0ef41Sopenharmony_ci // a. Let length be O.[[ArrayBufferByteLength]]. 491cb0ef41Sopenharmony_ci // 7. Return F(length); 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci if (IsResizableArrayBuffer(o)) { 521cb0ef41Sopenharmony_ci return Convert<Number>(o.max_byte_length); 531cb0ef41Sopenharmony_ci } 541cb0ef41Sopenharmony_ci return Convert<Number>(o.byte_length); 551cb0ef41Sopenharmony_ci} 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ci// #sec-get-arraybuffer.prototype.resizable 581cb0ef41Sopenharmony_citransitioning javascript builtin ArrayBufferPrototypeGetResizable( 591cb0ef41Sopenharmony_ci js-implicit context: NativeContext, receiver: JSAny)(): Boolean { 601cb0ef41Sopenharmony_ci // 1. Let O be the this value. 611cb0ef41Sopenharmony_ci // 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). 621cb0ef41Sopenharmony_ci const functionName = 'get ArrayBuffer.prototype.resizable'; 631cb0ef41Sopenharmony_ci const o = Cast<JSArrayBuffer>(receiver) otherwise 641cb0ef41Sopenharmony_ci ThrowTypeError( 651cb0ef41Sopenharmony_ci MessageTemplate::kIncompatibleMethodReceiver, functionName, receiver); 661cb0ef41Sopenharmony_ci // 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. 671cb0ef41Sopenharmony_ci if (IsSharedArrayBuffer(o)) { 681cb0ef41Sopenharmony_ci ThrowTypeError( 691cb0ef41Sopenharmony_ci MessageTemplate::kIncompatibleMethodReceiver, functionName, receiver); 701cb0ef41Sopenharmony_ci } 711cb0ef41Sopenharmony_ci // 4. Return IsResizableArrayBuffer(O). 721cb0ef41Sopenharmony_ci if (IsResizableArrayBuffer(o)) { 731cb0ef41Sopenharmony_ci return True; 741cb0ef41Sopenharmony_ci } 751cb0ef41Sopenharmony_ci return False; 761cb0ef41Sopenharmony_ci} 771cb0ef41Sopenharmony_ci 781cb0ef41Sopenharmony_ci// #sec-get-growablesharedarraybuffer.prototype.maxbytelength 791cb0ef41Sopenharmony_citransitioning javascript builtin 801cb0ef41Sopenharmony_ciSharedArrayBufferPrototypeGetMaxByteLength( 811cb0ef41Sopenharmony_ci js-implicit context: NativeContext, receiver: JSAny)(): Number { 821cb0ef41Sopenharmony_ci // 1. Let O be the this value. 831cb0ef41Sopenharmony_ci // 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). 841cb0ef41Sopenharmony_ci const functionName = 'get SharedArrayBuffer.prototype.maxByteLength'; 851cb0ef41Sopenharmony_ci const o = Cast<JSArrayBuffer>(receiver) otherwise 861cb0ef41Sopenharmony_ci ThrowTypeError( 871cb0ef41Sopenharmony_ci MessageTemplate::kIncompatibleMethodReceiver, functionName, receiver); 881cb0ef41Sopenharmony_ci // 3. If IsSharedArrayBuffer(O) is false, throw a TypeError exception. 891cb0ef41Sopenharmony_ci if (!IsSharedArrayBuffer(o)) { 901cb0ef41Sopenharmony_ci ThrowTypeError( 911cb0ef41Sopenharmony_ci MessageTemplate::kIncompatibleMethodReceiver, functionName, receiver); 921cb0ef41Sopenharmony_ci } 931cb0ef41Sopenharmony_ci // 4. If IsResizableArrayBuffer(O) is true, then 941cb0ef41Sopenharmony_ci // a. Let length be O.[[ArrayBufferMaxByteLength]]. 951cb0ef41Sopenharmony_ci // 5. Else, 961cb0ef41Sopenharmony_ci // a. Let length be O.[[ArrayBufferByteLength]]. 971cb0ef41Sopenharmony_ci // 6. Return F(length); 981cb0ef41Sopenharmony_ci dcheck(IsResizableArrayBuffer(o) || o.max_byte_length == o.byte_length); 991cb0ef41Sopenharmony_ci return Convert<Number>(o.max_byte_length); 1001cb0ef41Sopenharmony_ci} 1011cb0ef41Sopenharmony_ci 1021cb0ef41Sopenharmony_ci// #sec-get-sharedarraybuffer.prototype.growable 1031cb0ef41Sopenharmony_citransitioning javascript builtin SharedArrayBufferPrototypeGetGrowable( 1041cb0ef41Sopenharmony_ci js-implicit context: NativeContext, receiver: JSAny)(): Boolean { 1051cb0ef41Sopenharmony_ci // 1. Let O be the this value. 1061cb0ef41Sopenharmony_ci // 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). 1071cb0ef41Sopenharmony_ci const functionName = 'get SharedArrayBuffer.prototype.growable'; 1081cb0ef41Sopenharmony_ci const o = Cast<JSArrayBuffer>(receiver) otherwise 1091cb0ef41Sopenharmony_ci ThrowTypeError( 1101cb0ef41Sopenharmony_ci MessageTemplate::kIncompatibleMethodReceiver, functionName, receiver); 1111cb0ef41Sopenharmony_ci // 3. If IsSharedArrayBuffer(O) is false, throw a TypeError exception. 1121cb0ef41Sopenharmony_ci if (!IsSharedArrayBuffer(o)) { 1131cb0ef41Sopenharmony_ci ThrowTypeError( 1141cb0ef41Sopenharmony_ci MessageTemplate::kIncompatibleMethodReceiver, functionName, receiver); 1151cb0ef41Sopenharmony_ci } 1161cb0ef41Sopenharmony_ci // 4. Return IsResizableArrayBuffer(O). 1171cb0ef41Sopenharmony_ci if (IsResizableArrayBuffer(o)) { 1181cb0ef41Sopenharmony_ci return True; 1191cb0ef41Sopenharmony_ci } 1201cb0ef41Sopenharmony_ci return False; 1211cb0ef41Sopenharmony_ci} 1221cb0ef41Sopenharmony_ci 1231cb0ef41Sopenharmony_ci// #sec-arraybuffer.isview 1241cb0ef41Sopenharmony_citransitioning javascript builtin ArrayBufferIsView(arg: JSAny): Boolean { 1251cb0ef41Sopenharmony_ci // 1. If Type(arg) is not Object, return false. 1261cb0ef41Sopenharmony_ci // 2. If arg has a [[ViewedArrayBuffer]] internal slot, return true. 1271cb0ef41Sopenharmony_ci // 3. Return false. 1281cb0ef41Sopenharmony_ci typeswitch (arg) { 1291cb0ef41Sopenharmony_ci case (JSArrayBufferView): { 1301cb0ef41Sopenharmony_ci return True; 1311cb0ef41Sopenharmony_ci } 1321cb0ef41Sopenharmony_ci case (JSAny): { 1331cb0ef41Sopenharmony_ci return False; 1341cb0ef41Sopenharmony_ci } 1351cb0ef41Sopenharmony_ci } 1361cb0ef41Sopenharmony_ci} 1371cb0ef41Sopenharmony_ci 1381cb0ef41Sopenharmony_ci} // namespace arraybuffer 139