// -------------------------------------------------------------------
// Imports
+macro TYPED_ARRAYS(FUNCTION)
+// arrayIds below should be synchronized with Runtime_TypedArrayInitialize.
+FUNCTION(Uint8Array)
+FUNCTION(Int8Array)
+FUNCTION(Uint16Array)
+FUNCTION(Int16Array)
+FUNCTION(Uint32Array)
+FUNCTION(Int32Array)
+FUNCTION(Float32Array)
+FUNCTION(Float64Array)
+FUNCTION(Uint8ClampedArray)
+endmacro
macro DECLARE_GLOBALS(NAME)
var GlobalNAME = global.NAME;
endmacro
+TYPED_ARRAYS(DECLARE_GLOBALS)
DECLARE_GLOBALS(Array)
-DECLARE_GLOBALS(Uint8Array)
-DECLARE_GLOBALS(Int8Array)
-DECLARE_GLOBALS(Uint16Array)
-DECLARE_GLOBALS(Int16Array)
-DECLARE_GLOBALS(Uint32Array)
-DECLARE_GLOBALS(Int32Array)
-DECLARE_GLOBALS(Float32Array)
-DECLARE_GLOBALS(Float64Array)
-DECLARE_GLOBALS(Uint8ClampedArray)
var ArrayFrom;
var ArrayToString;
var IsNaN;
var MathMax;
var MathMin;
-var TypedArray = GlobalUint8Array.__proto__;
-var TypedArrayPrototype = GlobalUint8Array.prototype.__proto__;
utils.Import(function(from) {
ArrayFrom = from.ArrayFrom;
}
%FunctionSetLength(TypedArrayFrom, 1);
+// TODO(littledan): Fix the TypedArray proto chain (bug v8:4085).
+macro EXTEND_TYPED_ARRAY(NAME)
// Set up non-enumerable functions on the object.
-utils.InstallFunctions(TypedArray, DONT_ENUM | DONT_DELETE | READ_ONLY, [
- "from", TypedArrayFrom,
- "of", TypedArrayOf
-]);
-
-// Set up non-enumerable functions on the prototype object.
-utils.InstallFunctions(TypedArrayPrototype, DONT_ENUM, [
- "copyWithin", TypedArrayCopyWithin,
- "every", TypedArrayEvery,
- "fill", TypedArrayFill,
- "filter", TypedArrayFilter,
- "find", TypedArrayFind,
- "findIndex", TypedArrayFindIndex,
- "indexOf", TypedArrayIndexOf,
- "join", TypedArrayJoin,
- "lastIndexOf", TypedArrayLastIndexOf,
- "forEach", TypedArrayForEach,
- "map", TypedArrayMap,
- "reduce", TypedArrayReduce,
- "reduceRight", TypedArrayReduceRight,
- "reverse", TypedArrayReverse,
- "slice", TypedArraySlice,
- "some", TypedArraySome,
- "sort", TypedArraySort,
- "toString", TypedArrayToString,
- "toLocaleString", TypedArrayToLocaleString
-]);
+ utils.InstallFunctions(GlobalNAME, DONT_ENUM | DONT_DELETE | READ_ONLY, [
+ "from", TypedArrayFrom,
+ "of", TypedArrayOf
+ ]);
+
+ // Set up non-enumerable functions on the prototype object.
+ utils.InstallFunctions(GlobalNAME.prototype, DONT_ENUM, [
+ "copyWithin", TypedArrayCopyWithin,
+ "every", TypedArrayEvery,
+ "fill", TypedArrayFill,
+ "filter", TypedArrayFilter,
+ "find", TypedArrayFind,
+ "findIndex", TypedArrayFindIndex,
+ "indexOf", TypedArrayIndexOf,
+ "join", TypedArrayJoin,
+ "lastIndexOf", TypedArrayLastIndexOf,
+ "forEach", TypedArrayForEach,
+ "map", TypedArrayMap,
+ "reduce", TypedArrayReduce,
+ "reduceRight", TypedArrayReduceRight,
+ "reverse", TypedArrayReverse,
+ "slice", TypedArraySlice,
+ "some", TypedArraySome,
+ "sort", TypedArraySort,
+ "toString", TypedArrayToString,
+ "toLocaleString", TypedArrayToLocaleString
+ ]);
+endmacro
+
+TYPED_ARRAYS(EXTEND_TYPED_ARRAY)
})
}
-// Set the "prototype" property of a constructor Function.
RUNTIME_FUNCTION(Runtime_FunctionSetPrototype) {
HandleScope scope(isolate);
DCHECK(args.length() == 2);
}
-// Set the [[Prototype]] internal slot of an object.
RUNTIME_FUNCTION(Runtime_InternalSetPrototype) {
HandleScope scope(isolate);
DCHECK(args.length() == 2);
// --------------- Typed Arrays ---------------------
-function TypedArray() {
- if (!%_IsConstructCall()) {
- throw MakeTypeError(kConstructorNotFunction, "TypedArray")
- }
- // TODO(littledan): When the TypedArrays code is refactored to provide
- // a common constructor entrypoint for v8:4182, call that here.
-}
-
-function TypedArray_GetBuffer() {
- if (!%_IsTypedArray(this)) {
- throw MakeTypeError(kIncompatibleMethodReceiver, "TypedArray.buffer", this);
- }
- return %TypedArrayGetBuffer(this);
-}
-
-function TypedArray_GetByteLength() {
- if (!%_IsTypedArray(this)) {
- throw MakeTypeError(kIncompatibleMethodReceiver, "TypedArray.byteLength",
- this);
- }
- return %_ArrayBufferViewGetByteLength(this);
-}
-
-function TypedArray_GetByteOffset() {
- if (!%_IsTypedArray(this)) {
- throw MakeTypeError(kIncompatibleMethodReceiver, "TypedArray.byteOffset",
- this);
- }
- return %_ArrayBufferViewGetByteOffset(this);
-}
-
-function TypedArray_GetLength() {
- if (!%_IsTypedArray(this)) {
- throw MakeTypeError(kIncompatibleMethodReceiver, "TypedArray.length", this);
- }
- return %_TypedArrayGetLength(this);
-}
-
macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) {
if (!IS_UNDEFINED(byteOffset)) {
}
}
+function NAME_GetBuffer() {
+ if (!(%_ClassOf(this) === 'NAME')) {
+ throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.buffer", this);
+ }
+ return %TypedArrayGetBuffer(this);
+}
+
+function NAME_GetByteLength() {
+ if (!(%_ClassOf(this) === 'NAME')) {
+ throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.byteLength", this);
+ }
+ return %_ArrayBufferViewGetByteLength(this);
+}
+
+function NAME_GetByteOffset() {
+ if (!(%_ClassOf(this) === 'NAME')) {
+ throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.byteOffset", this);
+ }
+ return %_ArrayBufferViewGetByteOffset(this);
+}
+
+function NAME_GetLength() {
+ if (!(%_ClassOf(this) === 'NAME')) {
+ throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.length", this);
+ }
+ return %_TypedArrayGetLength(this);
+}
+
function NAMESubArray(begin, end) {
if (!(%_ClassOf(this) === 'NAME')) {
throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this);
// -------------------------------------------------------------------
-utils.InstallGetter(TypedArray.prototype, "buffer", TypedArray_GetBuffer);
-utils.InstallGetter(TypedArray.prototype, "byteOffset",
- TypedArray_GetByteOffset, DONT_ENUM);
-utils.InstallGetter(TypedArray.prototype, "byteLength",
- TypedArray_GetByteLength, DONT_ENUM);
-utils.InstallGetter(TypedArray.prototype, "length", TypedArray_GetLength,
- DONT_ENUM);
-utils.InstallGetter(TypedArray.prototype, symbolToStringTag,
- TypedArrayGetToStringTag, DONT_ENUM);
-utils.InstallFunctions(TypedArray.prototype, DONT_ENUM, [
- "set", TypedArraySet
-]);
-
macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
%SetCode(GlobalNAME, NAMEConstructor);
- %InternalSetPrototype(GlobalNAME, TypedArray);
- %FunctionSetPrototype(GlobalNAME, new TypedArray());
- %AddNamedProperty(GlobalNAME.prototype,
- "BYTES_PER_ELEMENT", ELEMENT_SIZE,
- READ_ONLY | DONT_ENUM | DONT_DELETE);
+ %FunctionSetPrototype(GlobalNAME, new GlobalObject());
%AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE,
READ_ONLY | DONT_ENUM | DONT_DELETE);
%AddNamedProperty(GlobalNAME.prototype,
"constructor", global.NAME, DONT_ENUM);
+ %AddNamedProperty(GlobalNAME.prototype,
+ "BYTES_PER_ELEMENT", ELEMENT_SIZE,
+ READ_ONLY | DONT_ENUM | DONT_DELETE);
+ utils.InstallGetter(GlobalNAME.prototype, "buffer", NAME_GetBuffer);
+ utils.InstallGetter(GlobalNAME.prototype, "byteOffset", NAME_GetByteOffset,
+ DONT_ENUM | DONT_DELETE);
+ utils.InstallGetter(GlobalNAME.prototype, "byteLength", NAME_GetByteLength,
+ DONT_ENUM | DONT_DELETE);
+ utils.InstallGetter(GlobalNAME.prototype, "length", NAME_GetLength,
+ DONT_ENUM | DONT_DELETE);
+ utils.InstallGetter(GlobalNAME.prototype, symbolToStringTag,
+ TypedArrayGetToStringTag);
utils.InstallFunctions(GlobalNAME.prototype, DONT_ENUM, [
- "subarray", NAMESubArray
+ "subarray", NAMESubArray,
+ "set", TypedArraySet
]);
endmacro
'use strict';
-function getPropertyDescriptor(object, field, expectedDepth) {
- for (var depth = 0; depth < expectedDepth; depth++) {
- assertFalse(Object.hasOwnProperty(object, field));
- object = object.__proto__;
- }
- return Object.getOwnPropertyDescriptor(object, field);
-}
-
-function assertGetterName(expected, object, name, expectedDepth) {
- var descr = getPropertyDescriptor(object, name, expectedDepth);
+function assertGetterName(expected, object, name) {
+ var descr = Object.getOwnPropertyDescriptor(object, name);
assertSame(expected, descr.get.name);
}
-function assertSetterName(expected, object, name, indirect) {
- var descr = getPropertyDescriptor(object, name);
+function assertSetterName(expected, object, name) {
+ var descr = Object.getOwnPropertyDescriptor(object, name);
assertSame(expected, descr.set.name);
}
];
for (let f of typedArrays) {
- assertGetterName('get buffer', f.prototype, 'buffer', 1);
- assertGetterName('get byteOffset', f.prototype, 'byteOffset', 1);
- assertGetterName('get byteLength', f.prototype, 'byteLength', 1);
- assertGetterName('get length', f.prototype, 'length', 1);
- assertGetterName('get [Symbol.toStringTag]', f.prototype, Symbol.toStringTag, 1);
+ assertGetterName('get buffer', f.prototype, 'buffer');
+ assertGetterName('get byteOffset', f.prototype, 'byteOffset');
+ assertGetterName('get byteLength', f.prototype, 'byteLength');
+ assertGetterName('get length', f.prototype, 'length');
+ assertGetterName('get [Symbol.toStringTag]', f.prototype, Symbol.toStringTag);
}
// DataView,
Date,
Error,
+ Float32Array,
+ Float64Array,
Function,
+ Int16Array,
+ Int32Array,
+ Int8Array,
Map,
Number,
Object,
Set,
String,
// Symbol, not constructible
+ Uint16Array,
+ Uint32Array,
+ Uint8Array,
+ Uint8ClampedArray,
WeakMap,
WeakSet,
];
assertPrototypeOf(new f(), f.prototype);
}
-var typedArrayConstructors = [
- Float32Array,
- Float64Array,
- Int16Array,
- Int32Array,
- Int8Array,
- Uint16Array,
- Uint32Array,
- Uint8Array,
- Uint8ClampedArray,
-];
-
-for (var t of typedArrayConstructors) {
- assertPrototypeOf(t, Uint8Array.__proto__);
- assertPrototypeOf(new t(), t.prototype);
-}
-
var p = new Promise(function() {});
assertPrototypeOf(p, Promise.prototype);
return new constr(sab);
}
-function getPropertyDescriptor(object, field, expectedDepth) {
- for (var depth = 0; depth < expectedDepth; depth++) {
- assertFalse(Object.hasOwnProperty(object, field));
- object = object.__proto__;
- }
- return Object.getOwnPropertyDescriptor(object, field);
-}
-
function TestTypedArray(constr, elementSize, typicalElement) {
assertSame(elementSize, constr.BYTES_PER_ELEMENT);
var a = new constr(sab, 64*elementSize, 128);
assertEquals("[object " + constr.name + "]",
Object.prototype.toString.call(a));
- var desc = getPropertyDescriptor(constr.prototype, Symbol.toStringTag, 1);
+ var desc = Object.getOwnPropertyDescriptor(
+ constr.prototype, Symbol.toStringTag);
assertTrue(desc.configurable);
assertFalse(desc.enumerable);
assertFalse(!!desc.writable);
function TestPropertyTypeChecks(constructor) {
function CheckProperty(name) {
- var d = getPropertyDescriptor(constructor.prototype, name, 1);
+ var d = Object.getOwnPropertyDescriptor(constructor.prototype, name);
var o = {};
assertThrows(function() {d.get.call(o);}, TypeError);
for (var i = 0; i < typedArrayConstructors.length; i++) {
var ctor = typedArrayConstructors[i];
var a = MakeSharedTypedArray(ctor, 10);
- d.get.call(a); // shouldn't throw on any type
+ if (ctor === constructor) {
+ d.get.call(a); // shouldn't throw
+ } else {
+ assertThrows(function() {d.get.call(a);}, TypeError);
+ }
}
}
Int32Array,
Uint8ClampedArray,
Float32Array,
- Float64Array
-];
+ Float64Array];
-function getPropertyDescriptor(object, field, expectedDepth) {
- for (var depth = 0; depth < expectedDepth; depth++) {
- assertFalse(Object.hasOwnProperty(object, field));
- object = object.__proto__;
- }
- return Object.getOwnPropertyDescriptor(object, field);
-}
function TestTypedArrayOf(constructor) {
// %TypedArray%.of basics.
assertEquals("pass", status);
// Check superficial features of %TypedArray%.of.
- var desc = getPropertyDescriptor(constructor, "of", 1);
+ var desc = Object.getOwnPropertyDescriptor(constructor, "of");
assertEquals(desc.configurable, false);
assertEquals(desc.enumerable, false);
// Typed arrays
-function getPropertyDescriptor(object, field, expectedDepth) {
- for (var depth = 0; depth < expectedDepth; depth++) {
- assertFalse(Object.hasOwnProperty(object, field));
- object = object.__proto__;
- }
- return Object.getOwnPropertyDescriptor(object, field);
-}
-
function TestTypedArray(constr, elementSize, typicalElement) {
assertSame(elementSize, constr.BYTES_PER_ELEMENT);
var a = new constr(ab, 64*elementSize, 128);
assertEquals("[object " + constr.name + "]",
Object.prototype.toString.call(a));
- var desc = getPropertyDescriptor(constr.prototype, Symbol.toStringTag, 1);
+ var desc = Object.getOwnPropertyDescriptor(
+ constr.prototype, Symbol.toStringTag);
assertTrue(desc.configurable);
assertFalse(desc.enumerable);
assertFalse(!!desc.writable);
function TestPropertyTypeChecks(constructor) {
function CheckProperty(name) {
- var d = getPropertyDescriptor(constructor.prototype, name, 1);
+ var d = Object.getOwnPropertyDescriptor(constructor.prototype, name);
var o = {};
assertThrows(function() {d.get.call(o);}, TypeError);
for (var i = 0; i < typedArrayConstructors.length; i++) {
var ctor = typedArrayConstructors[i];
var a = new ctor(10);
- d.get.call(a); // shouldn't throw, even from a different type
+ if (ctor === constructor) {
+ d.get.call(a); // shouldn't throw
+ } else {
+ assertThrows(function() {d.get.call(a);}, TypeError);
+ }
}
}
assertEquals(undefined, get(a));
})();
+// Ensure we cannot delete length, byteOffset, byteLength.
+assertTrue(Int32Array.prototype.hasOwnProperty("length"));
+assertTrue(Int32Array.prototype.hasOwnProperty("byteOffset"));
+assertTrue(Int32Array.prototype.hasOwnProperty("byteLength"));
+assertFalse(delete Int32Array.prototype.length);
+assertFalse(delete Int32Array.prototype.byteOffset);
+assertFalse(delete Int32Array.prototype.byteLength);
+
a = new Int32Array(100);
get = function(a) {
assertEquals(0, get(a));
%OptimizeFunctionOnNextCall(get);
assertEquals(0, get(a));
-
-// Ensure we can delete length, byteOffset, byteLength.
-for (var name of ['length', 'byteOffset', 'byteLength', 'buffer']) {
- var property = Object.getOwnPropertyDescriptor(
- Int32Array.prototype.__proto__, name);
- assertEquals("object", typeof property);
- assertEquals(true, property.configurable);
- assertEquals(false, property.enumerable);
- assertEquals("function", typeof property.get);
-}