Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Unified Diff: src/typedarray.js

Issue 1186733002: Add %TypedArray% to proto chain (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/typedarray.js
diff --git a/src/typedarray.js b/src/typedarray.js
index 65659147ee7777cf1e8bc69196d4fc09a4beee89..fbf4bbd0eefb2bd1d8647ea89d35f1794e9210b1 100644
--- a/src/typedarray.js
+++ b/src/typedarray.js
@@ -45,6 +45,36 @@ utils.Import(function(from) {
// --------------- Typed Arrays ---------------------
+function TypedArray() { }
+
+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.buffer", this);
adamk 2015/06/13 00:49:38 s/buffer/byteLength/
Dan Ehrenberg 2015/06/13 05:54:09 Done.
+ }
+ return %_ArrayBufferViewGetByteLength(this);
+}
+
+function TypedArray_GetByteOffset() {
+ if (!%IsTypedArray(this)) {
+ throw MakeTypeError(kIncompatibleMethodReceiver, "TypedArray.buffer", this);
adamk 2015/06/13 00:49:38 byteOffset
Dan Ehrenberg 2015/06/13 05:54:09 Done.
+ }
+ return %_ArrayBufferViewGetByteOffset(this);
+}
+
+function TypedArray_GetLength() {
+ if (!%IsTypedArray(this)) {
adamk 2015/06/13 00:49:38 I don't know if we can afford a runtime call for t
Dan Ehrenberg 2015/06/13 05:54:09 This is sort of unrelated to v8:4182, except in th
+ throw MakeTypeError(kIncompatibleMethodReceiver, "TypedArray.buffer", this);
adamk 2015/06/13 00:49:38 length
Dan Ehrenberg 2015/06/13 05:54:09 Done.
+ }
+ return %_TypedArrayGetLength(this);
+}
+
macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) {
if (!IS_UNDEFINED(byteOffset)) {
@@ -145,34 +175,6 @@ function NAMEConstructor(arg1, arg2, arg3) {
}
}
-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);
@@ -320,29 +322,33 @@ function TypedArrayGetToStringTag() {
// -------------------------------------------------------------------
+utils.InstallGetter(TypedArray.prototype, "buffer", TypedArray_GetBuffer);
+utils.InstallGetter(TypedArray.prototype, "byteOffset", TypedArray_GetByteOffset,
adamk 2015/06/13 00:49:38 Nit: wrap at 80 chars (I don't know why we don't h
Dan Ehrenberg 2015/06/13 05:54:09 Done.
+ DONT_ENUM | DONT_DELETE);
+utils.InstallGetter(TypedArray.prototype, "byteLength", TypedArray_GetByteLength,
+ DONT_ENUM | DONT_DELETE);
+utils.InstallGetter(TypedArray.prototype, "length", TypedArray_GetLength,
+ DONT_ENUM | DONT_DELETE);
+utils.InstallGetter(TypedArray.prototype, symbolToStringTag,
+ TypedArrayGetToStringTag);
+utils.InstallFunctions(TypedArray.prototype, DONT_ENUM, [
+ "set", TypedArraySet
+]);
+
macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
%SetCode(GlobalNAME, NAMEConstructor);
- %FunctionSetPrototype(GlobalNAME, new GlobalObject());
+ %InternalSetPrototype(GlobalNAME, TypedArray);
+ %FunctionSetPrototype(GlobalNAME, new TypedArray());
+ %AddNamedProperty(GlobalNAME.prototype,
+ "BYTES_PER_ELEMENT", ELEMENT_SIZE,
+ READ_ONLY | DONT_ENUM | DONT_DELETE);
%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,
- "set", TypedArraySet
+ "subarray", NAMESubArray
adamk 2015/06/13 00:49:38 I'm guessing this is also blocked on issue 4182?
Dan Ehrenberg 2015/06/13 05:54:09 Yep.
]);
endmacro
@@ -479,4 +485,12 @@ utils.InstallFunctions(GlobalDataView.prototype, DONT_ENUM, [
"setFloat64", DataViewSetFloat64JS
]);
+// -------------------------------------------------------------------
+// Exports
+
+utils.Export(function(to) {
+ to.TypedArray = TypedArray;
+ to.TypedArrayPrototype = TypedArray.prototype;
+});
+
})

Powered by Google App Engine
This is Rietveld 408576698