Added an extra flag that enables only ArrayBuffer.
This makes Blink experimentation easier. R=rossberg@chromium.org Review URL: https://codereview.chromium.org/14884012 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14560 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
c74ee804b3
commit
9b45b71d5a
100
src/arraybuffer.js
Normal file
100
src/arraybuffer.js
Normal file
@ -0,0 +1,100 @@
|
||||
// Copyright 2013 the V8 project authors. All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
"use strict";
|
||||
|
||||
var $ArrayBuffer = global.ArrayBuffer;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function ArrayBufferConstructor(byteLength) { // length = 1
|
||||
if (%_IsConstructCall()) {
|
||||
var l = TO_POSITIVE_INTEGER(byteLength);
|
||||
%ArrayBufferInitialize(this, l);
|
||||
} else {
|
||||
return new $ArrayBuffer(byteLength);
|
||||
}
|
||||
}
|
||||
|
||||
function ArrayBufferGetByteLength() {
|
||||
if (!IS_ARRAYBUFFER(this)) {
|
||||
throw MakeTypeError('incompatible_method_receiver',
|
||||
['ArrayBuffer.prototype.byteLength', this]);
|
||||
}
|
||||
return %ArrayBufferGetByteLength(this);
|
||||
}
|
||||
|
||||
// ES6 Draft 15.13.5.5.3
|
||||
function ArrayBufferSlice(start, end) {
|
||||
if (!IS_ARRAYBUFFER(this)) {
|
||||
throw MakeTypeError('incompatible_method_receiver',
|
||||
['ArrayBuffer.prototype.slice', this]);
|
||||
}
|
||||
|
||||
var relativeStart = TO_INTEGER(start);
|
||||
var first;
|
||||
if (relativeStart < 0) {
|
||||
first = MathMax(this.byteLength + relativeStart, 0);
|
||||
} else {
|
||||
first = MathMin(relativeStart, this.byteLength);
|
||||
}
|
||||
var relativeEnd = IS_UNDEFINED(end) ? this.byteLength : TO_INTEGER(end);
|
||||
var fin;
|
||||
if (relativeEnd < 0) {
|
||||
fin = MathMax(this.byteLength + relativeEnd, 0);
|
||||
} else {
|
||||
fin = MathMin(relativeEnd, this.byteLength);
|
||||
}
|
||||
|
||||
var newLen = fin - first;
|
||||
// TODO(dslomov): implement inheritance
|
||||
var result = new $ArrayBuffer(newLen);
|
||||
|
||||
%ArrayBufferSliceImpl(this, result, first);
|
||||
return result;
|
||||
}
|
||||
|
||||
function SetUpArrayBuffer() {
|
||||
%CheckIsBootstrapping();
|
||||
|
||||
// Set up the ArrayBuffer constructor function.
|
||||
%SetCode($ArrayBuffer, ArrayBufferConstructor);
|
||||
%FunctionSetPrototype($ArrayBuffer, new $Object());
|
||||
|
||||
// Set up the constructor property on the ArrayBuffer prototype object.
|
||||
%SetProperty($ArrayBuffer.prototype, "constructor", $ArrayBuffer, DONT_ENUM);
|
||||
|
||||
InstallGetter($ArrayBuffer.prototype, "byteLength", ArrayBufferGetByteLength);
|
||||
|
||||
InstallFunctions($ArrayBuffer.prototype, DONT_ENUM, $Array(
|
||||
"slice", ArrayBufferSlice
|
||||
));
|
||||
}
|
||||
|
||||
SetUpArrayBuffer();
|
||||
|
||||
|
@ -1317,36 +1317,36 @@ void Genesis::InitializeExperimentalGlobal() {
|
||||
}
|
||||
}
|
||||
|
||||
if (FLAG_harmony_array_buffer) {
|
||||
// -- A r r a y B u f f e r
|
||||
Handle<JSFunction> array_buffer_fun =
|
||||
InstallFunction(global, "ArrayBuffer", JS_ARRAY_BUFFER_TYPE,
|
||||
JSArrayBuffer::kSize,
|
||||
isolate()->initial_object_prototype(),
|
||||
Builtins::kIllegal, true);
|
||||
native_context()->set_array_buffer_fun(*array_buffer_fun);
|
||||
}
|
||||
|
||||
if (FLAG_harmony_typed_arrays) {
|
||||
{ // -- A r r a y B u f f e r
|
||||
Handle<JSFunction> array_buffer_fun =
|
||||
InstallFunction(global, "ArrayBuffer", JS_ARRAY_BUFFER_TYPE,
|
||||
JSArrayBuffer::kSize,
|
||||
isolate()->initial_object_prototype(),
|
||||
Builtins::kIllegal, true);
|
||||
native_context()->set_array_buffer_fun(*array_buffer_fun);
|
||||
}
|
||||
{
|
||||
// -- T y p e d A r r a y s
|
||||
Handle<JSFunction> int8_fun = InstallTypedArray("Int8Array");
|
||||
native_context()->set_int8_array_fun(*int8_fun);
|
||||
Handle<JSFunction> uint8_fun = InstallTypedArray("Uint8Array");
|
||||
native_context()->set_uint8_array_fun(*uint8_fun);
|
||||
Handle<JSFunction> int16_fun = InstallTypedArray("Int16Array");
|
||||
native_context()->set_int16_array_fun(*int16_fun);
|
||||
Handle<JSFunction> uint16_fun = InstallTypedArray("Uint16Array");
|
||||
native_context()->set_uint16_array_fun(*uint16_fun);
|
||||
Handle<JSFunction> int32_fun = InstallTypedArray("Int32Array");
|
||||
native_context()->set_int32_array_fun(*int32_fun);
|
||||
Handle<JSFunction> uint32_fun = InstallTypedArray("Uint32Array");
|
||||
native_context()->set_uint32_array_fun(*uint32_fun);
|
||||
Handle<JSFunction> float_fun = InstallTypedArray("Float32Array");
|
||||
native_context()->set_float_array_fun(*float_fun);
|
||||
Handle<JSFunction> double_fun = InstallTypedArray("Float64Array");
|
||||
native_context()->set_double_array_fun(*double_fun);
|
||||
Handle<JSFunction> uint8c_fun = InstallTypedArray("Uint8ClampedArray");
|
||||
native_context()->set_uint8c_array_fun(*uint8c_fun);
|
||||
}
|
||||
// -- T y p e d A r r a y s
|
||||
Handle<JSFunction> int8_fun = InstallTypedArray("Int8Array");
|
||||
native_context()->set_int8_array_fun(*int8_fun);
|
||||
Handle<JSFunction> uint8_fun = InstallTypedArray("Uint8Array");
|
||||
native_context()->set_uint8_array_fun(*uint8_fun);
|
||||
Handle<JSFunction> int16_fun = InstallTypedArray("Int16Array");
|
||||
native_context()->set_int16_array_fun(*int16_fun);
|
||||
Handle<JSFunction> uint16_fun = InstallTypedArray("Uint16Array");
|
||||
native_context()->set_uint16_array_fun(*uint16_fun);
|
||||
Handle<JSFunction> int32_fun = InstallTypedArray("Int32Array");
|
||||
native_context()->set_int32_array_fun(*int32_fun);
|
||||
Handle<JSFunction> uint32_fun = InstallTypedArray("Uint32Array");
|
||||
native_context()->set_uint32_array_fun(*uint32_fun);
|
||||
Handle<JSFunction> float_fun = InstallTypedArray("Float32Array");
|
||||
native_context()->set_float_array_fun(*float_fun);
|
||||
Handle<JSFunction> double_fun = InstallTypedArray("Float64Array");
|
||||
native_context()->set_double_array_fun(*double_fun);
|
||||
Handle<JSFunction> uint8c_fun = InstallTypedArray("Uint8ClampedArray");
|
||||
native_context()->set_uint8c_array_fun(*uint8c_fun);
|
||||
}
|
||||
|
||||
if (FLAG_harmony_generators) {
|
||||
@ -1992,6 +1992,11 @@ bool Genesis::InstallExperimentalNatives() {
|
||||
"native object-observe.js") == 0) {
|
||||
if (!CompileExperimentalBuiltin(isolate(), i)) return false;
|
||||
}
|
||||
if (FLAG_harmony_array_buffer &&
|
||||
strcmp(ExperimentalNatives::GetScriptName(i).start(),
|
||||
"native arraybuffer.js") == 0) {
|
||||
if (!CompileExperimentalBuiltin(isolate(), i)) return false;
|
||||
}
|
||||
if (FLAG_harmony_typed_arrays &&
|
||||
strcmp(ExperimentalNatives::GetScriptName(i).start(),
|
||||
"native typedarray.js") == 0) {
|
||||
|
@ -166,6 +166,9 @@ DEFINE_bool(harmony_observation, false,
|
||||
"enable harmony object observation (implies harmony collections")
|
||||
DEFINE_bool(harmony_typed_arrays, false,
|
||||
"enable harmony typed arrays")
|
||||
DEFINE_bool(harmony_array_buffer, false,
|
||||
"enable harmony array buffer")
|
||||
DEFINE_implication(harmony_typed_arrays, harmony_array_buffer)
|
||||
DEFINE_bool(harmony_generators, false, "enable harmony generators")
|
||||
DEFINE_bool(harmony, false, "enable all harmony features (except typeof)")
|
||||
DEFINE_implication(harmony, harmony_scoping)
|
||||
|
@ -31,56 +31,7 @@
|
||||
// in runtime.js:
|
||||
// var $Array = global.Array;
|
||||
|
||||
var $ArrayBuffer = global.ArrayBuffer;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function ArrayBufferConstructor(byteLength) { // length = 1
|
||||
if (%_IsConstructCall()) {
|
||||
var l = TO_POSITIVE_INTEGER(byteLength);
|
||||
%ArrayBufferInitialize(this, l);
|
||||
} else {
|
||||
return new $ArrayBuffer(byteLength);
|
||||
}
|
||||
}
|
||||
|
||||
function ArrayBufferGetByteLength() {
|
||||
if (!IS_ARRAYBUFFER(this)) {
|
||||
throw MakeTypeError('incompatible_method_receiver',
|
||||
['ArrayBuffer.prototype.byteLength', this]);
|
||||
}
|
||||
return %ArrayBufferGetByteLength(this);
|
||||
}
|
||||
|
||||
// ES6 Draft 15.13.5.5.3
|
||||
function ArrayBufferSlice(start, end) {
|
||||
if (!IS_ARRAYBUFFER(this)) {
|
||||
throw MakeTypeError('incompatible_method_receiver',
|
||||
['ArrayBuffer.prototype.slice', this]);
|
||||
}
|
||||
|
||||
var relativeStart = TO_INTEGER(start);
|
||||
var first;
|
||||
if (relativeStart < 0) {
|
||||
first = MathMax(this.byteLength + relativeStart, 0);
|
||||
} else {
|
||||
first = MathMin(relativeStart, this.byteLength);
|
||||
}
|
||||
var relativeEnd = IS_UNDEFINED(end) ? this.byteLength : TO_INTEGER(end);
|
||||
var fin;
|
||||
if (relativeEnd < 0) {
|
||||
fin = MathMax(this.byteLength + relativeEnd, 0);
|
||||
} else {
|
||||
fin = MathMin(relativeEnd, this.byteLength);
|
||||
}
|
||||
|
||||
var newLen = fin - first;
|
||||
// TODO(dslomov): implement inheritance
|
||||
var result = new $ArrayBuffer(newLen);
|
||||
|
||||
%ArrayBufferSliceImpl(this, result, first);
|
||||
return result;
|
||||
}
|
||||
|
||||
// --------------- Typed Arrays ---------------------
|
||||
|
||||
@ -119,7 +70,7 @@ function CreateTypedArrayConstructor(name, elementSize, arrayId, constructor) {
|
||||
function ConstructByLength(obj, length) {
|
||||
var l = IS_UNDEFINED(length) ? 0 : TO_POSITIVE_INTEGER(length);
|
||||
var byteLength = l * elementSize;
|
||||
var buffer = new $ArrayBuffer(byteLength);
|
||||
var buffer = new global.ArrayBuffer(byteLength);
|
||||
%TypedArrayInitialize(obj, arrayId, buffer, 0, byteLength);
|
||||
}
|
||||
|
||||
@ -197,25 +148,6 @@ function CreateSubArray(elementSize, constructor) {
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function SetUpArrayBuffer() {
|
||||
%CheckIsBootstrapping();
|
||||
|
||||
// Set up the ArrayBuffer constructor function.
|
||||
%SetCode($ArrayBuffer, ArrayBufferConstructor);
|
||||
%FunctionSetPrototype($ArrayBuffer, new $Object());
|
||||
|
||||
// Set up the constructor property on the ArrayBuffer prototype object.
|
||||
%SetProperty($ArrayBuffer.prototype, "constructor", $ArrayBuffer, DONT_ENUM);
|
||||
|
||||
InstallGetter($ArrayBuffer.prototype, "byteLength", ArrayBufferGetByteLength);
|
||||
|
||||
InstallFunctions($ArrayBuffer.prototype, DONT_ENUM, $Array(
|
||||
"slice", ArrayBufferSlice
|
||||
));
|
||||
}
|
||||
|
||||
SetUpArrayBuffer();
|
||||
|
||||
function SetupTypedArray(arrayId, name, constructor, elementSize) {
|
||||
%CheckIsBootstrapping();
|
||||
var fun = CreateTypedArrayConstructor(name, elementSize,
|
||||
|
@ -2257,6 +2257,7 @@ THREADED_TEST(SymbolProperties) {
|
||||
|
||||
|
||||
THREADED_TEST(ArrayBuffer) {
|
||||
i::FLAG_harmony_array_buffer = true;
|
||||
i::FLAG_harmony_typed_arrays = true;
|
||||
|
||||
LocalContext env;
|
||||
@ -15107,6 +15108,7 @@ template <typename ElementType, typename TypedArray,
|
||||
void TypedArrayTestHelper(v8::ExternalArrayType array_type,
|
||||
int64_t low, int64_t high) {
|
||||
const int kElementCount = 50;
|
||||
i::FLAG_harmony_array_buffer = true;
|
||||
i::FLAG_harmony_typed_arrays = true;
|
||||
|
||||
LocalContext env;
|
||||
@ -15191,6 +15193,7 @@ THREADED_TEST(Uint8ClampedArray) {
|
||||
|
||||
#define IS_TYPED_ARRAY_TEST(TypedArray) \
|
||||
THREADED_TEST(Is##TypedArray) { \
|
||||
i::FLAG_harmony_array_buffer = true; \
|
||||
i::FLAG_harmony_typed_arrays = true; \
|
||||
LocalContext env; \
|
||||
v8::Isolate* isolate = env->GetIsolate(); \
|
||||
|
@ -800,6 +800,7 @@
|
||||
'../../src/proxy.js',
|
||||
'../../src/collection.js',
|
||||
'../../src/object-observe.js',
|
||||
'../../src/arraybuffer.js',
|
||||
'../../src/typedarray.js',
|
||||
'../../src/generator.js'
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user