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

Unified Diff: src/api.cc

Issue 641343005: Share code between Factory::NewJSTypedArray and API (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 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 | « no previous file | src/factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 4929fdaa465a5ab772f6ba3e98dd3352d33f3adf..b190925ca042e6a508b91fbafdb9c61fdbce5eb5 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -6100,78 +6100,22 @@ size_t v8::TypedArray::Length() {
}
-static inline void SetupArrayBufferView(
- i::Isolate* isolate,
- i::Handle<i::JSArrayBufferView> obj,
- i::Handle<i::JSArrayBuffer> buffer,
- size_t byte_offset,
- size_t byte_length) {
- DCHECK(byte_offset + byte_length <=
- static_cast<size_t>(buffer->byte_length()->Number()));
-
- obj->set_buffer(*buffer);
-
- obj->set_weak_next(buffer->weak_first_view());
- buffer->set_weak_first_view(*obj);
-
- i::Handle<i::Object> byte_offset_object =
- isolate->factory()->NewNumberFromSize(byte_offset);
- obj->set_byte_offset(*byte_offset_object);
-
- i::Handle<i::Object> byte_length_object =
- isolate->factory()->NewNumberFromSize(byte_length);
- obj->set_byte_length(*byte_length_object);
-}
-
-template<typename ElementType,
- ExternalArrayType array_type,
- i::ElementsKind elements_kind>
-i::Handle<i::JSTypedArray> NewTypedArray(
- i::Isolate* isolate,
- Handle<ArrayBuffer> array_buffer, size_t byte_offset, size_t length) {
- i::Handle<i::JSTypedArray> obj =
- isolate->factory()->NewJSTypedArray(array_type);
- i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer);
-
- DCHECK(byte_offset % sizeof(ElementType) == 0);
-
- CHECK(length <= (std::numeric_limits<size_t>::max() / sizeof(ElementType)));
- CHECK(length <= static_cast<size_t>(i::Smi::kMaxValue));
- size_t byte_length = length * sizeof(ElementType);
- SetupArrayBufferView(
- isolate, obj, buffer, byte_offset, byte_length);
-
- i::Handle<i::Object> length_object =
- isolate->factory()->NewNumberFromSize(length);
- obj->set_length(*length_object);
-
- i::Handle<i::ExternalArray> elements =
- isolate->factory()->NewExternalArray(
- static_cast<int>(length), array_type,
- static_cast<uint8_t*>(buffer->backing_store()) + byte_offset);
- i::Handle<i::Map> map =
- i::JSObject::GetElementsTransitionMap(obj, elements_kind);
- i::JSObject::SetMapAndElements(obj, map, elements);
- return obj;
-}
-
-
#define TYPED_ARRAY_NEW(Type, type, TYPE, ctype, size) \
Local<Type##Array> Type##Array::New(Handle<ArrayBuffer> array_buffer, \
- size_t byte_offset, size_t length) { \
+ size_t byte_offset, size_t length) { \
i::Isolate* isolate = Utils::OpenHandle(*array_buffer)->GetIsolate(); \
LOG_API(isolate, \
- "v8::" #Type "Array::New(Handle<ArrayBuffer>, size_t, size_t)"); \
+ "v8::" #Type "Array::New(Handle<ArrayBuffer>, size_t, size_t)"); \
ENTER_V8(isolate); \
if (!Utils::ApiCheck(length <= static_cast<size_t>(i::Smi::kMaxValue), \
- "v8::" #Type "Array::New(Handle<ArrayBuffer>, size_t, size_t)", \
- "length exceeds max allowed value")) { \
- return Local<Type##Array>(); \
+ "v8::" #Type \
+ "Array::New(Handle<ArrayBuffer>, size_t, size_t)", \
+ "length exceeds max allowed value")) { \
+ return Local<Type##Array>(); \
} \
- i::Handle<i::JSTypedArray> obj = \
- NewTypedArray<ctype, v8::kExternal##Type##Array, \
- i::EXTERNAL_##TYPE##_ELEMENTS>( \
- isolate, array_buffer, byte_offset, length); \
+ i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); \
+ i::Handle<i::JSTypedArray> obj = isolate->factory()->NewJSTypedArray( \
+ v8::kExternal##Type##Array, buffer, byte_offset, length); \
return Utils::ToLocal##Type##Array(obj); \
}
@@ -6185,9 +6129,8 @@ Local<DataView> DataView::New(Handle<ArrayBuffer> array_buffer,
i::Isolate* isolate = buffer->GetIsolate();
LOG_API(isolate, "v8::DataView::New(void*, size_t, size_t)");
ENTER_V8(isolate);
- i::Handle<i::JSDataView> obj = isolate->factory()->NewJSDataView();
- SetupArrayBufferView(
- isolate, obj, buffer, byte_offset, byte_length);
+ i::Handle<i::JSDataView> obj =
+ isolate->factory()->NewJSDataView(buffer, byte_offset, byte_length);
return Utils::ToLocal(obj);
}
« no previous file with comments | « no previous file | src/factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698