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

Unified Diff: src/typedarray.js

Issue 216993002: Revert "Inline internal getters for typed arrays & friends." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 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
« no previous file with comments | « src/spaces.cc ('k') | test/mjsunit/harmony/typedarrays.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/typedarray.js
diff --git a/src/typedarray.js b/src/typedarray.js
index e86c86cb880c8bbb2f5b49e0d3be84370b121c5e..109d627008daeb7115c60196aabbafadc84edeca 100644
--- a/src/typedarray.js
+++ b/src/typedarray.js
@@ -57,7 +57,7 @@ macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
length = ToPositiveInteger(length, "invalid_typed_array_length");
}
- var bufferByteLength = %_ArrayBufferGetByteLength(buffer);
+ var bufferByteLength = %ArrayBufferGetByteLength(buffer);
var offset;
if (IS_UNDEFINED(byteOffset)) {
offset = 0;
@@ -125,6 +125,7 @@ macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
}
function NAMEConstructor(arg1, arg2, arg3) {
+
if (%_IsConstructCall()) {
if (IS_ARRAYBUFFER(arg1)) {
NAMEConstructByArrayBuffer(this, arg1, arg2, arg3);
@@ -138,52 +139,34 @@ macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
throw MakeTypeError("constructor_not_function", ["NAME"])
}
}
+endmacro
- function NAME_GetBuffer() {
- if (!(%_ClassOf(this) === 'NAME')) {
- throw MakeTypeError('incompatible_method_receiver',
- ["NAME.buffer", this]);
- }
- return %TypedArrayGetBuffer(this);
- }
+TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR)
- function NAME_GetByteLength() {
- if (!(%_ClassOf(this) === 'NAME')) {
- throw MakeTypeError('incompatible_method_receiver',
- ["NAME.byteLength", this]);
- }
- return %_ArrayBufferViewGetByteLength(this);
- }
+function TypedArrayGetBuffer() {
+ return %TypedArrayGetBuffer(this);
+}
- function NAME_GetByteOffset() {
- if (!(%_ClassOf(this) === 'NAME')) {
- throw MakeTypeError('incompatible_method_receiver',
- ["NAME.byteOffset", this]);
- }
- return %_ArrayBufferViewGetByteOffset(this);
- }
+function TypedArrayGetByteLength() {
+ return %TypedArrayGetByteLength(this);
+}
- function NAME_GetLength() {
- if (!(%_ClassOf(this) === 'NAME')) {
- throw MakeTypeError('incompatible_method_receiver',
- ["NAME.length", this]);
- }
- return %_TypedArrayGetLength(this);
- }
+function TypedArrayGetByteOffset() {
+ return %TypedArrayGetByteOffset(this);
+}
- var $NAME = global.NAME;
+function TypedArrayGetLength() {
+ return %TypedArrayGetLength(this);
+}
- function NAMESubArray(begin, end) {
- if (!(%_ClassOf(this) === 'NAME')) {
- throw MakeTypeError('incompatible_method_receiver',
- ["NAME.subarray", this]);
- }
+function CreateSubArray(elementSize, constructor) {
+ return function(begin, end) {
var beginInt = TO_INTEGER(begin);
if (!IS_UNDEFINED(end)) {
end = TO_INTEGER(end);
}
- var srcLength = %_TypedArrayGetLength(this);
+ var srcLength = %TypedArrayGetLength(this);
if (beginInt < 0) {
beginInt = MathMax(0, srcLength + beginInt);
} else {
@@ -201,14 +184,11 @@ macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
}
var newLength = endInt - beginInt;
var beginByteOffset =
- %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE;
- return new $NAME(%TypedArrayGetBuffer(this),
- beginByteOffset, newLength);
+ %TypedArrayGetByteOffset(this) + beginInt * elementSize;
+ return new constructor(%TypedArrayGetBuffer(this),
+ beginByteOffset, newLength);
}
-endmacro
-
-TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR)
-
+}
function TypedArraySetFromArrayLike(target, source, sourceLength, offset) {
if (offset > 0) {
@@ -316,34 +296,34 @@ function TypedArraySet(obj, offset) {
// -------------------------------------------------------------------
-function SetupTypedArrays() {
-macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
+function SetupTypedArray(constructor, fun, elementSize) {
%CheckIsBootstrapping();
- %SetCode(global.NAME, NAMEConstructor);
- %FunctionSetPrototype(global.NAME, new $Object());
+ %SetCode(constructor, fun);
+ %FunctionSetPrototype(constructor, new $Object());
- %SetProperty(global.NAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE,
+ %SetProperty(constructor, "BYTES_PER_ELEMENT", elementSize,
READ_ONLY | DONT_ENUM | DONT_DELETE);
- %SetProperty(global.NAME.prototype,
- "constructor", global.NAME, DONT_ENUM);
- %SetProperty(global.NAME.prototype,
- "BYTES_PER_ELEMENT", ELEMENT_SIZE,
+ %SetProperty(constructor.prototype,
+ "constructor", constructor, DONT_ENUM);
+ %SetProperty(constructor.prototype,
+ "BYTES_PER_ELEMENT", elementSize,
READ_ONLY | DONT_ENUM | DONT_DELETE);
- InstallGetter(global.NAME.prototype, "buffer", NAME_GetBuffer);
- InstallGetter(global.NAME.prototype, "byteOffset", NAME_GetByteOffset);
- InstallGetter(global.NAME.prototype, "byteLength", NAME_GetByteLength);
- InstallGetter(global.NAME.prototype, "length", NAME_GetLength);
+ InstallGetter(constructor.prototype, "buffer", TypedArrayGetBuffer);
+ InstallGetter(constructor.prototype, "byteOffset", TypedArrayGetByteOffset);
+ InstallGetter(constructor.prototype, "byteLength", TypedArrayGetByteLength);
+ InstallGetter(constructor.prototype, "length", TypedArrayGetLength);
- InstallFunctions(global.NAME.prototype, DONT_ENUM, $Array(
- "subarray", NAMESubArray,
+ InstallFunctions(constructor.prototype, DONT_ENUM, $Array(
+ "subarray", CreateSubArray(elementSize, constructor),
"set", TypedArraySet
));
+}
+
+macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
+ SetupTypedArray (global.NAME, NAMEConstructor, ELEMENT_SIZE);
endmacro
TYPED_ARRAYS(SETUP_TYPED_ARRAY)
-}
-
-SetupTypedArrays();
// --------------------------- DataView -----------------------------
@@ -361,7 +341,7 @@ function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3
byteLength = TO_INTEGER(byteLength);
}
- var bufferByteLength = %_ArrayBufferGetByteLength(buffer);
+ var bufferByteLength = %ArrayBufferGetByteLength(buffer);
var offset = IS_UNDEFINED(byteOffset) ? 0 : byteOffset;
if (offset > bufferByteLength) {
@@ -393,7 +373,7 @@ function DataViewGetByteOffset() {
throw MakeTypeError('incompatible_method_receiver',
['DataView.byteOffset', this]);
}
- return %_ArrayBufferViewGetByteOffset(this);
+ return %DataViewGetByteOffset(this);
}
function DataViewGetByteLength() {
@@ -401,7 +381,7 @@ function DataViewGetByteLength() {
throw MakeTypeError('incompatible_method_receiver',
['DataView.byteLength', this]);
}
- return %_ArrayBufferViewGetByteLength(this);
+ return %DataViewGetByteLength(this);
}
macro DATA_VIEW_TYPES(FUNCTION)
« no previous file with comments | « src/spaces.cc ('k') | test/mjsunit/harmony/typedarrays.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698