ENTER_V8(i_isolate);
i::Handle<i::JSArrayBuffer> obj =
i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared);
- i::Runtime::SetupArrayBufferAllocatingData(i_isolate, obj, byte_length);
+ i::JSArrayBuffer::SetupAllocatingData(obj, i_isolate, byte_length);
return Utils::ToLocal(obj);
}
ENTER_V8(i_isolate);
i::Handle<i::JSArrayBuffer> obj =
i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared);
- i::Runtime::SetupArrayBuffer(i_isolate, obj,
- mode == ArrayBufferCreationMode::kExternalized,
- data, byte_length);
+ i::JSArrayBuffer::Setup(obj, i_isolate,
+ mode == ArrayBufferCreationMode::kExternalized, data,
+ byte_length);
return Utils::ToLocal(obj);
}
ENTER_V8(i_isolate);
i::Handle<i::JSArrayBuffer> obj =
i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kShared);
- i::Runtime::SetupArrayBufferAllocatingData(i_isolate, obj, byte_length, true,
- i::SharedFlag::kShared);
+ i::JSArrayBuffer::SetupAllocatingData(obj, i_isolate, byte_length, true,
+ i::SharedFlag::kShared);
return Utils::ToLocalShared(obj);
}
ENTER_V8(i_isolate);
i::Handle<i::JSArrayBuffer> obj =
i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kShared);
- i::Runtime::SetupArrayBuffer(i_isolate, obj,
- mode == ArrayBufferCreationMode::kExternalized,
- data, byte_length, i::SharedFlag::kShared);
+ i::JSArrayBuffer::Setup(obj, i_isolate,
+ mode == ArrayBufferCreationMode::kExternalized, data,
+ byte_length, i::SharedFlag::kShared);
return Utils::ToLocalShared(obj);
}
data = reinterpret_cast<Data*>(
isolate->array_buffer_allocator()->Allocate(byte_length));
}
- Runtime::SetupArrayBuffer(isolate, buffer, is_external, data, byte_length);
+ JSArrayBuffer::Setup(buffer, isolate, is_external, data, byte_length);
Handle<JSTypedArray> typed_array =
isolate->factory()->NewJSTypedArray(type, buffer, 0, num_elements);
obj->set_length(*length_object);
Handle<JSArrayBuffer> buffer = isolate()->factory()->NewJSArrayBuffer();
- Runtime::SetupArrayBuffer(isolate(), buffer, true, NULL, byte_length,
- SharedFlag::kNotShared);
+ JSArrayBuffer::Setup(buffer, isolate(), true, NULL, byte_length,
+ SharedFlag::kNotShared);
obj->set_buffer(*buffer);
Handle<FixedTypedArrayBase> elements =
isolate()->factory()->NewFixedTypedArray(
}
+void JSArrayBuffer::Setup(Handle<JSArrayBuffer> array_buffer, Isolate* isolate,
+ bool is_external, void* data, size_t allocated_length,
+ SharedFlag shared) {
+ DCHECK(array_buffer->GetInternalFieldCount() ==
+ v8::ArrayBuffer::kInternalFieldCount);
+ for (int i = 0; i < v8::ArrayBuffer::kInternalFieldCount; i++) {
+ array_buffer->SetInternalField(i, Smi::FromInt(0));
+ }
+ array_buffer->set_backing_store(data);
+ array_buffer->set_bit_field(0);
+ array_buffer->set_is_external(is_external);
+ array_buffer->set_is_neuterable(shared == SharedFlag::kNotShared);
+ array_buffer->set_is_shared(shared == SharedFlag::kShared);
+
+ if (data && !is_external) {
+ isolate->heap()->RegisterNewArrayBuffer(
+ isolate->heap()->InNewSpace(*array_buffer), data, allocated_length);
+ }
+
+ Handle<Object> byte_length =
+ isolate->factory()->NewNumberFromSize(allocated_length);
+ CHECK(byte_length->IsSmi() || byte_length->IsHeapNumber());
+ array_buffer->set_byte_length(*byte_length);
+}
+
+
+bool JSArrayBuffer::SetupAllocatingData(Handle<JSArrayBuffer> array_buffer,
+ Isolate* isolate,
+ size_t allocated_length,
+ bool initialize, SharedFlag shared) {
+ void* data;
+ CHECK(isolate->array_buffer_allocator() != NULL);
+ // Prevent creating array buffers when serializing.
+ DCHECK(!isolate->serializer_enabled());
+ if (allocated_length != 0) {
+ if (initialize) {
+ data = isolate->array_buffer_allocator()->Allocate(allocated_length);
+ } else {
+ data = isolate->array_buffer_allocator()->AllocateUninitialized(
+ allocated_length);
+ }
+ if (data == NULL) return false;
+ } else {
+ data = NULL;
+ }
+
+ JSArrayBuffer::Setup(array_buffer, isolate, false, data, allocated_length,
+ shared);
+ return true;
+}
+
+
Handle<JSArrayBuffer> JSTypedArray::MaterializeArrayBuffer(
Handle<JSTypedArray> typed_array) {
void Neuter();
+ static void Setup(Handle<JSArrayBuffer> array_buffer, Isolate* isolate,
+ bool is_external, void* data, size_t allocated_length,
+ SharedFlag shared = SharedFlag::kNotShared);
+
+ static bool SetupAllocatingData(Handle<JSArrayBuffer> array_buffer,
+ Isolate* isolate, size_t allocated_length,
+ bool initialize = true,
+ SharedFlag shared = SharedFlag::kNotShared);
+
// Dispatched behavior.
DECLARE_PRINTER(JSArrayBuffer)
DECLARE_VERIFIER(JSArrayBuffer)
namespace v8 {
namespace internal {
-void Runtime::SetupArrayBuffer(Isolate* isolate,
- Handle<JSArrayBuffer> array_buffer,
- bool is_external, void* data,
- size_t allocated_length, SharedFlag shared) {
- DCHECK(array_buffer->GetInternalFieldCount() ==
- v8::ArrayBuffer::kInternalFieldCount);
- for (int i = 0; i < v8::ArrayBuffer::kInternalFieldCount; i++) {
- array_buffer->SetInternalField(i, Smi::FromInt(0));
- }
- array_buffer->set_backing_store(data);
- array_buffer->set_bit_field(0);
- array_buffer->set_is_external(is_external);
- array_buffer->set_is_neuterable(shared == SharedFlag::kNotShared);
- array_buffer->set_is_shared(shared == SharedFlag::kShared);
-
- if (data && !is_external) {
- isolate->heap()->RegisterNewArrayBuffer(
- isolate->heap()->InNewSpace(*array_buffer), data, allocated_length);
- }
-
- Handle<Object> byte_length =
- isolate->factory()->NewNumberFromSize(allocated_length);
- CHECK(byte_length->IsSmi() || byte_length->IsHeapNumber());
- array_buffer->set_byte_length(*byte_length);
-}
-
-
-bool Runtime::SetupArrayBufferAllocatingData(Isolate* isolate,
- Handle<JSArrayBuffer> array_buffer,
- size_t allocated_length,
- bool initialize,
- SharedFlag shared) {
- void* data;
- CHECK(isolate->array_buffer_allocator() != NULL);
- // Prevent creating array buffers when serializing.
- DCHECK(!isolate->serializer_enabled());
- if (allocated_length != 0) {
- if (initialize) {
- data = isolate->array_buffer_allocator()->Allocate(allocated_length);
- } else {
- data = isolate->array_buffer_allocator()->AllocateUninitialized(
- allocated_length);
- }
- if (data == NULL) return false;
- } else {
- data = NULL;
- }
-
- SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length,
- shared);
- return true;
-}
-
RUNTIME_FUNCTION(Runtime_ArrayBufferInitialize) {
HandleScope scope(isolate);
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength));
}
- if (!Runtime::SetupArrayBufferAllocatingData(
- isolate, holder, allocated_length, true,
+ if (!JSArrayBuffer::SetupAllocatingData(
+ holder, isolate, allocated_length, true,
is_shared ? SharedFlag::kShared : SharedFlag::kNotShared)) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength));
holder->set_elements(*elements);
} else {
Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer();
- Runtime::SetupArrayBuffer(isolate, buffer, true, NULL, byte_length,
- SharedFlag::kNotShared);
+ JSArrayBuffer::Setup(buffer, isolate, true, NULL, byte_length,
+ SharedFlag::kNotShared);
holder->set_buffer(*buffer);
Handle<FixedTypedArrayBase> elements =
isolate->factory()->NewFixedTypedArray(static_cast<int>(length),
//
// TODO(dslomov): revise this once we support subclassing.
- if (!Runtime::SetupArrayBufferAllocatingData(isolate, buffer, byte_length,
- false)) {
+ if (!JSArrayBuffer::SetupAllocatingData(buffer, isolate, byte_length,
+ false)) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength));
}
};
-class JavaScriptFrameIterator; // Forward declaration.
-
-
class Runtime : public AllStatic {
public:
enum FunctionId {
MUST_USE_RESULT static MaybeHandle<Name> ToName(Isolate* isolate,
Handle<Object> key);
- static void SetupArrayBuffer(Isolate* isolate,
- Handle<JSArrayBuffer> array_buffer,
- bool is_external, void* data,
- size_t allocated_length,
- SharedFlag shared = SharedFlag::kNotShared);
-
- static bool SetupArrayBufferAllocatingData(
- Isolate* isolate, Handle<JSArrayBuffer> array_buffer,
- size_t allocated_length, bool initialize = true,
- SharedFlag shared = SharedFlag::kNotShared);
-
enum TypedArrayId {
// arrayIds below should be synchronized with typedarray.js natives.
ARRAY_ID_UINT8 = 1,
t.GenerateCode();
Handle<JSArrayBuffer> array = t.factory()->NewJSArrayBuffer();
- Runtime::SetupArrayBufferAllocatingData(t.isolate(), array, array_length);
+ JSArrayBuffer::SetupAllocatingData(array, t.isolate(), array_length);
uint8_t* data = reinterpret_cast<uint8_t*>(array->backing_store());
for (int i = 0; i < array_length; i++) {
data[i] = i;
Handle<JSArrayBuffer> NewArrayBuffer(void* bytes, size_t byte_length) {
Handle<JSArrayBuffer> buffer = factory()->NewJSArrayBuffer();
- Runtime::SetupArrayBuffer(isolate(), buffer, true, bytes, byte_length);
+ JSArrayBuffer::Setup(buffer, isolate(), true, bytes, byte_length);
return buffer;
}