Index: src/js/typedarray.js |
diff --git a/src/js/typedarray.js b/src/js/typedarray.js |
index 7d8a08d052750dc15cbbc53d0fdda44438d16ded..6c858236a826c9a626819af7cd63a347136a776a 100644 |
--- a/src/js/typedarray.js |
+++ b/src/js/typedarray.js |
@@ -21,7 +21,6 @@ |
var GlobalArrayBufferPrototype = GlobalArrayBuffer.prototype; |
var GlobalDataView = global.DataView; |
var GlobalObject = global.Object; |
-var GlobalTypedArray = global.TypedArray; |
var InnerArrayCopyWithin; |
var InnerArrayEvery; |
var InnerArrayFill; |
@@ -330,6 +329,42 @@ |
} |
%SetForceInlineFlag(TypedArraySubArray); |
+function TypedArrayGetBuffer() { |
+ if (!IS_TYPEDARRAY(this)) { |
+ throw MakeTypeError(kIncompatibleMethodReceiver, |
+ "get TypedArray.prototype.buffer", this); |
+ } |
+ return %TypedArrayGetBuffer(this); |
+} |
+%SetForceInlineFlag(TypedArrayGetBuffer); |
+ |
+function TypedArrayGetByteLength() { |
+ if (!IS_TYPEDARRAY(this)) { |
+ throw MakeTypeError(kIncompatibleMethodReceiver, |
+ "get TypedArray.prototype.byteLength", this); |
+ } |
+ return %_ArrayBufferViewGetByteLength(this); |
+} |
+%SetForceInlineFlag(TypedArrayGetByteLength); |
+ |
+function TypedArrayGetByteOffset() { |
+ if (!IS_TYPEDARRAY(this)) { |
+ throw MakeTypeError(kIncompatibleMethodReceiver, |
+ "get TypedArray.prototype.byteOffset", this); |
+ } |
+ return %_ArrayBufferViewGetByteOffset(this); |
+} |
+%SetForceInlineFlag(TypedArrayGetByteOffset); |
+ |
+function TypedArrayGetLength() { |
+ if (!IS_TYPEDARRAY(this)) { |
+ throw MakeTypeError(kIncompatibleMethodReceiver, |
+ "get TypedArray.prototype.length", this); |
+ } |
+ return %_TypedArrayGetLength(this); |
+} |
+%SetForceInlineFlag(TypedArrayGetLength); |
+ |
function TypedArraySetFromArrayLike(target, source, sourceLength, offset) { |
@@ -773,26 +808,33 @@ |
} |
%FunctionSetLength(TypedArrayFrom, 1); |
-// TODO(bmeurer): Migrate this to a proper builtin. |
-function TypedArrayConstructor() { |
+function TypedArray() { |
if (IS_UNDEFINED(new.target)) { |
throw MakeTypeError(kConstructorNonCallable, "TypedArray"); |
} |
- if (new.target === GlobalTypedArray) { |
+ if (new.target === TypedArray) { |
throw MakeTypeError(kConstructAbstractClass, "TypedArray"); |
} |
} |
// ------------------------------------------------------------------- |
-%SetCode(GlobalTypedArray, TypedArrayConstructor); |
-utils.InstallFunctions(GlobalTypedArray, DONT_ENUM, [ |
+%FunctionSetPrototype(TypedArray, new GlobalObject()); |
+%AddNamedProperty(TypedArray.prototype, |
+ "constructor", TypedArray, DONT_ENUM); |
+utils.InstallFunctions(TypedArray, DONT_ENUM, [ |
"from", TypedArrayFrom, |
"of", TypedArrayOf |
]); |
-utils.InstallGetter(GlobalTypedArray.prototype, toStringTagSymbol, |
+utils.InstallGetter(TypedArray.prototype, "buffer", TypedArrayGetBuffer); |
+utils.InstallGetter(TypedArray.prototype, "byteOffset", |
+ TypedArrayGetByteOffset); |
+utils.InstallGetter(TypedArray.prototype, "byteLength", |
+ TypedArrayGetByteLength); |
+utils.InstallGetter(TypedArray.prototype, "length", TypedArrayGetLength); |
+utils.InstallGetter(TypedArray.prototype, toStringTagSymbol, |
TypedArrayGetToStringTag); |
-utils.InstallFunctions(GlobalTypedArray.prototype, DONT_ENUM, [ |
+utils.InstallFunctions(TypedArray.prototype, DONT_ENUM, [ |
"subarray", TypedArraySubArray, |
"set", TypedArraySet, |
"copyWithin", TypedArrayCopyWithin, |
@@ -816,15 +858,15 @@ |
"toLocaleString", TypedArrayToLocaleString |
]); |
-%AddNamedProperty(GlobalTypedArray.prototype, "toString", ArrayToString, |
+%AddNamedProperty(TypedArray.prototype, "toString", ArrayToString, |
DONT_ENUM); |
macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) |
%SetCode(GlobalNAME, NAMEConstructor); |
%FunctionSetPrototype(GlobalNAME, new GlobalObject()); |
- %InternalSetPrototype(GlobalNAME, GlobalTypedArray); |
- %InternalSetPrototype(GlobalNAME.prototype, GlobalTypedArray.prototype); |
+ %InternalSetPrototype(GlobalNAME, TypedArray); |
+ %InternalSetPrototype(GlobalNAME.prototype, TypedArray.prototype); |
%AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
READ_ONLY | DONT_ENUM | DONT_DELETE); |
@@ -839,6 +881,29 @@ |
TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
// --------------------------- DataView ----------------------------- |
+ |
+function DataViewGetBufferJS() { |
+ if (!IS_DATAVIEW(this)) { |
+ throw MakeTypeError(kIncompatibleMethodReceiver, 'DataView.buffer', this); |
+ } |
+ return %DataViewGetBuffer(this); |
+} |
+ |
+function DataViewGetByteOffset() { |
+ if (!IS_DATAVIEW(this)) { |
+ throw MakeTypeError(kIncompatibleMethodReceiver, |
+ 'DataView.byteOffset', this); |
+ } |
+ return %_ArrayBufferViewGetByteOffset(this); |
+} |
+ |
+function DataViewGetByteLength() { |
+ if (!IS_DATAVIEW(this)) { |
+ throw MakeTypeError(kIncompatibleMethodReceiver, |
+ 'DataView.byteLength', this); |
+ } |
+ return %_ArrayBufferViewGetByteLength(this); |
+} |
macro DATA_VIEW_TYPES(FUNCTION) |
FUNCTION(Int8) |
@@ -878,6 +943,21 @@ |
DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER) |
+// Setup the DataView constructor. |
+%FunctionSetPrototype(GlobalDataView, new GlobalObject); |
+ |
+// Set up constructor property on the DataView prototype. |
+%AddNamedProperty(GlobalDataView.prototype, "constructor", GlobalDataView, |
+ DONT_ENUM); |
+%AddNamedProperty(GlobalDataView.prototype, toStringTagSymbol, "DataView", |
+ READ_ONLY|DONT_ENUM); |
+ |
+utils.InstallGetter(GlobalDataView.prototype, "buffer", DataViewGetBufferJS); |
+utils.InstallGetter(GlobalDataView.prototype, "byteOffset", |
+ DataViewGetByteOffset); |
+utils.InstallGetter(GlobalDataView.prototype, "byteLength", |
+ DataViewGetByteLength); |
+ |
utils.InstallFunctions(GlobalDataView.prototype, DONT_ENUM, [ |
"getInt8", DataViewGetInt8JS, |
"setInt8", DataViewSetInt8JS, |