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

Side by Side Diff: src/api.cc

Issue 17155014: API for DataView. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/api.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2576 matching lines...) Expand 10 before | Expand all | Expand 10 after
2587 } 2587 }
2588 2588
2589 2589
2590 bool Value::IsArrayBuffer() const { 2590 bool Value::IsArrayBuffer() const {
2591 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArrayBuffer()")) 2591 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArrayBuffer()"))
2592 return false; 2592 return false;
2593 return Utils::OpenHandle(this)->IsJSArrayBuffer(); 2593 return Utils::OpenHandle(this)->IsJSArrayBuffer();
2594 } 2594 }
2595 2595
2596 2596
2597 bool Value::IsArrayBufferView() const {
2598 return Utils::OpenHandle(this)->IsJSArrayBufferView();
2599 }
2600
2601
2597 bool Value::IsTypedArray() const { 2602 bool Value::IsTypedArray() const {
2598 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArrayBuffer()")) 2603 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArrayBuffer()"))
2599 return false; 2604 return false;
2600 return Utils::OpenHandle(this)->IsJSTypedArray(); 2605 return Utils::OpenHandle(this)->IsJSTypedArray();
2601 } 2606 }
2602 2607
2603 2608
2604 #define TYPED_ARRAY_LIST(F) \ 2609 #define TYPED_ARRAY_LIST(F) \
2605 F(Uint8Array, kExternalUnsignedByteArray) \ 2610 F(Uint8Array, kExternalUnsignedByteArray) \
2606 F(Int8Array, kExternalByteArray) \ 2611 F(Int8Array, kExternalByteArray) \
(...skipping 13 matching lines...) Expand all
2620 i::Handle<i::Object> obj = Utils::OpenHandle(this); \ 2625 i::Handle<i::Object> obj = Utils::OpenHandle(this); \
2621 if (!obj->IsJSTypedArray()) return false; \ 2626 if (!obj->IsJSTypedArray()) return false; \
2622 return i::JSTypedArray::cast(*obj)->type() == type_const; \ 2627 return i::JSTypedArray::cast(*obj)->type() == type_const; \
2623 } 2628 }
2624 2629
2625 TYPED_ARRAY_LIST(VALUE_IS_TYPED_ARRAY) 2630 TYPED_ARRAY_LIST(VALUE_IS_TYPED_ARRAY)
2626 2631
2627 #undef VALUE_IS_TYPED_ARRAY 2632 #undef VALUE_IS_TYPED_ARRAY
2628 2633
2629 2634
2635 bool Value::IsDataView() const {
2636 return Utils::OpenHandle(this)->IsJSDataView();
2637 }
2638
2639
2630 bool Value::IsObject() const { 2640 bool Value::IsObject() const {
2631 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsObject()")) return false; 2641 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsObject()")) return false;
2632 return Utils::OpenHandle(this)->IsJSObject(); 2642 return Utils::OpenHandle(this)->IsJSObject();
2633 } 2643 }
2634 2644
2635 2645
2636 bool Value::IsNumber() const { 2646 bool Value::IsNumber() const {
2637 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsNumber()")) return false; 2647 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsNumber()")) return false;
2638 return Utils::OpenHandle(this)->IsNumber(); 2648 return Utils::OpenHandle(this)->IsNumber();
2639 } 2649 }
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
2966 2976
2967 void v8::ArrayBuffer::CheckCast(Value* that) { 2977 void v8::ArrayBuffer::CheckCast(Value* that) {
2968 if (IsDeadCheck(i::Isolate::Current(), "v8::ArrayBuffer::Cast()")) return; 2978 if (IsDeadCheck(i::Isolate::Current(), "v8::ArrayBuffer::Cast()")) return;
2969 i::Handle<i::Object> obj = Utils::OpenHandle(that); 2979 i::Handle<i::Object> obj = Utils::OpenHandle(that);
2970 ApiCheck(obj->IsJSArrayBuffer(), 2980 ApiCheck(obj->IsJSArrayBuffer(),
2971 "v8::ArrayBuffer::Cast()", 2981 "v8::ArrayBuffer::Cast()",
2972 "Could not convert to ArrayBuffer"); 2982 "Could not convert to ArrayBuffer");
2973 } 2983 }
2974 2984
2975 2985
2986 void v8::ArrayBufferView::CheckCast(Value* that) {
2987 i::Handle<i::Object> obj = Utils::OpenHandle(that);
2988 ApiCheck(obj->IsJSArrayBufferView(),
2989 "v8::ArrayBufferView::Cast()",
2990 "Could not convert to ArrayBufferView");
2991 }
2992
2993
2976 void v8::TypedArray::CheckCast(Value* that) { 2994 void v8::TypedArray::CheckCast(Value* that) {
2977 if (IsDeadCheck(i::Isolate::Current(), "v8::TypedArray::Cast()")) return; 2995 if (IsDeadCheck(i::Isolate::Current(), "v8::TypedArray::Cast()")) return;
2978 i::Handle<i::Object> obj = Utils::OpenHandle(that); 2996 i::Handle<i::Object> obj = Utils::OpenHandle(that);
2979 ApiCheck(obj->IsJSTypedArray(), 2997 ApiCheck(obj->IsJSTypedArray(),
2980 "v8::TypedArray::Cast()", 2998 "v8::TypedArray::Cast()",
2981 "Could not convert to TypedArray"); 2999 "Could not convert to TypedArray");
2982 } 3000 }
2983 3001
2984 3002
2985 #define CHECK_TYPED_ARRAY_CAST(ApiClass, typeConst) \ 3003 #define CHECK_TYPED_ARRAY_CAST(ApiClass, typeConst) \
2986 void v8::ApiClass::CheckCast(Value* that) { \ 3004 void v8::ApiClass::CheckCast(Value* that) { \
2987 if (IsDeadCheck(i::Isolate::Current(), "v8::" #ApiClass "::Cast()")) \ 3005 if (IsDeadCheck(i::Isolate::Current(), "v8::" #ApiClass "::Cast()")) \
2988 return; \ 3006 return; \
2989 i::Handle<i::Object> obj = Utils::OpenHandle(that); \ 3007 i::Handle<i::Object> obj = Utils::OpenHandle(that); \
2990 ApiCheck(obj->IsJSTypedArray() && \ 3008 ApiCheck(obj->IsJSTypedArray() && \
2991 i::JSTypedArray::cast(*obj)->type() == typeConst, \ 3009 i::JSTypedArray::cast(*obj)->type() == typeConst, \
2992 "v8::" #ApiClass "::Cast()", \ 3010 "v8::" #ApiClass "::Cast()", \
2993 "Could not convert to " #ApiClass); \ 3011 "Could not convert to " #ApiClass); \
2994 } 3012 }
2995 3013
2996 3014
2997 TYPED_ARRAY_LIST(CHECK_TYPED_ARRAY_CAST) 3015 TYPED_ARRAY_LIST(CHECK_TYPED_ARRAY_CAST)
2998 3016
2999 #undef CHECK_TYPED_ARRAY_CAST 3017 #undef CHECK_TYPED_ARRAY_CAST
3000 3018
3001 3019
3020 void v8::DataView::CheckCast(Value* that) {
3021 i::Handle<i::Object> obj = Utils::OpenHandle(that);
3022 ApiCheck(obj->IsJSDataView(),
3023 "v8::DataView::Cast()",
3024 "Could not convert to DataView");
3025 }
3026
3027
3002 void v8::Date::CheckCast(v8::Value* that) { 3028 void v8::Date::CheckCast(v8::Value* that) {
3003 i::Isolate* isolate = i::Isolate::Current(); 3029 i::Isolate* isolate = i::Isolate::Current();
3004 if (IsDeadCheck(isolate, "v8::Date::Cast()")) return; 3030 if (IsDeadCheck(isolate, "v8::Date::Cast()")) return;
3005 i::Handle<i::Object> obj = Utils::OpenHandle(that); 3031 i::Handle<i::Object> obj = Utils::OpenHandle(that);
3006 ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Date_string()), 3032 ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Date_string()),
3007 "v8::Date::Cast()", 3033 "v8::Date::Cast()",
3008 "Could not convert to date"); 3034 "Could not convert to date");
3009 } 3035 }
3010 3036
3011 3037
(...skipping 3211 matching lines...) Expand 10 before | Expand all | Expand 10 after
6223 EnsureInitializedForIsolate(isolate, "v8::ArrayBuffer::New(void*, size_t)"); 6249 EnsureInitializedForIsolate(isolate, "v8::ArrayBuffer::New(void*, size_t)");
6224 LOG_API(isolate, "v8::ArrayBuffer::New(void*, size_t)"); 6250 LOG_API(isolate, "v8::ArrayBuffer::New(void*, size_t)");
6225 ENTER_V8(isolate); 6251 ENTER_V8(isolate);
6226 i::Handle<i::JSArrayBuffer> obj = 6252 i::Handle<i::JSArrayBuffer> obj =
6227 isolate->factory()->NewJSArrayBuffer(); 6253 isolate->factory()->NewJSArrayBuffer();
6228 i::Runtime::SetupArrayBuffer(isolate, obj, true, data, byte_length); 6254 i::Runtime::SetupArrayBuffer(isolate, obj, true, data, byte_length);
6229 return Utils::ToLocal(obj); 6255 return Utils::ToLocal(obj);
6230 } 6256 }
6231 6257
6232 6258
6233 Local<ArrayBuffer> v8::TypedArray::Buffer() { 6259 Local<ArrayBuffer> v8::ArrayBufferView::Buffer() {
6234 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 6260 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
6235 if (IsDeadCheck(isolate, "v8::TypedArray::Buffer()"))
6236 return Local<ArrayBuffer>();
6237 i::Handle<i::JSTypedArray> obj = Utils::OpenHandle(this);
6238 ASSERT(obj->buffer()->IsJSArrayBuffer()); 6261 ASSERT(obj->buffer()->IsJSArrayBuffer());
6239 i::Handle<i::JSArrayBuffer> buffer(i::JSArrayBuffer::cast(obj->buffer())); 6262 i::Handle<i::JSArrayBuffer> buffer(i::JSArrayBuffer::cast(obj->buffer()));
6240 return Utils::ToLocal(buffer); 6263 return Utils::ToLocal(buffer);
6241 } 6264 }
6242 6265
6243 6266
6244 size_t v8::TypedArray::ByteOffset() { 6267 size_t v8::ArrayBufferView::ByteOffset() {
6245 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 6268 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
6246 if (IsDeadCheck(isolate, "v8::TypedArray::ByteOffset()")) return 0;
6247 i::Handle<i::JSTypedArray> obj = Utils::OpenHandle(this);
6248 return static_cast<size_t>(obj->byte_offset()->Number()); 6269 return static_cast<size_t>(obj->byte_offset()->Number());
6249 } 6270 }
6250 6271
6251 6272
6252 size_t v8::TypedArray::ByteLength() { 6273 size_t v8::ArrayBufferView::ByteLength() {
6253 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 6274 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
6254 if (IsDeadCheck(isolate, "v8::TypedArray::ByteLength()")) return 0;
6255 i::Handle<i::JSTypedArray> obj = Utils::OpenHandle(this);
6256 return static_cast<size_t>(obj->byte_length()->Number()); 6275 return static_cast<size_t>(obj->byte_length()->Number());
6257 } 6276 }
6258 6277
6259 6278
6279 void* v8::ArrayBufferView::BaseAddress() {
6280 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
6281 i::Handle<i::JSArrayBuffer> buffer(i::JSArrayBuffer::cast(obj->buffer()));
6282 void* buffer_data = buffer->backing_store();
6283 size_t byte_offset = static_cast<size_t>(obj->byte_offset()->Number());
6284 return static_cast<uint8_t*>(buffer_data) + byte_offset;
6285 }
6286
6287
6260 size_t v8::TypedArray::Length() { 6288 size_t v8::TypedArray::Length() {
6261 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 6289 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
6262 if (IsDeadCheck(isolate, "v8::TypedArray::Length()")) return 0; 6290 if (IsDeadCheck(isolate, "v8::TypedArray::Length()")) return 0;
6263 i::Handle<i::JSTypedArray> obj = Utils::OpenHandle(this); 6291 i::Handle<i::JSTypedArray> obj = Utils::OpenHandle(this);
6264 return static_cast<size_t>(obj->length()->Number()); 6292 return static_cast<size_t>(obj->length()->Number());
6265 } 6293 }
6266 6294
6267 6295
6268 void* v8::TypedArray::BaseAddress() { 6296 static inline void SetupArrayBufferView(
6269 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 6297 i::Isolate* isolate,
6270 if (IsDeadCheck(isolate, "v8::TypedArray::BaseAddress()")) return NULL; 6298 i::Handle<i::JSArrayBufferView> obj,
6271 i::Handle<i::JSTypedArray> obj = Utils::OpenHandle(this); 6299 i::Handle<i::JSArrayBuffer> buffer,
6272 i::Handle<i::JSArrayBuffer> buffer(i::JSArrayBuffer::cast(obj->buffer())); 6300 size_t byte_offset,
6273 void* buffer_data = buffer->backing_store(); 6301 size_t byte_length) {
6274 size_t byte_offset = static_cast<size_t>(obj->byte_offset()->Number()); 6302 ASSERT(byte_offset + byte_length <=
6275 return static_cast<uint8_t*>(buffer_data) + byte_offset; 6303 static_cast<size_t>(buffer->byte_length()->Number()));
6304
6305 obj->set_buffer(*buffer);
6306
6307 obj->set_weak_next(buffer->weak_first_view());
6308 buffer->set_weak_first_view(*obj);
6309
6310 i::Handle<i::Object> byte_offset_object =
6311 isolate->factory()->NewNumberFromSize(byte_offset);
6312 obj->set_byte_offset(*byte_offset_object);
6313
6314 i::Handle<i::Object> byte_length_object =
6315 isolate->factory()->NewNumberFromSize(byte_length);
6316 obj->set_byte_length(*byte_length_object);
6276 } 6317 }
6277 6318
6278
6279 template<typename ElementType, 6319 template<typename ElementType,
6280 ExternalArrayType array_type, 6320 ExternalArrayType array_type,
6281 i::ElementsKind elements_kind> 6321 i::ElementsKind elements_kind>
6282 i::Handle<i::JSTypedArray> NewTypedArray( 6322 i::Handle<i::JSTypedArray> NewTypedArray(
6283 i::Isolate* isolate, 6323 i::Isolate* isolate,
6284 Handle<ArrayBuffer> array_buffer, size_t byte_offset, size_t length) { 6324 Handle<ArrayBuffer> array_buffer, size_t byte_offset, size_t length) {
6285 i::Handle<i::JSTypedArray> obj = 6325 i::Handle<i::JSTypedArray> obj =
6286 isolate->factory()->NewJSTypedArray(array_type); 6326 isolate->factory()->NewJSTypedArray(array_type);
6287 i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); 6327 i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer);
6288 6328
6289 ASSERT(byte_offset % sizeof(ElementType) == 0); 6329 ASSERT(byte_offset % sizeof(ElementType) == 0);
6290 ASSERT(byte_offset + length * sizeof(ElementType) <=
6291 static_cast<size_t>(buffer->byte_length()->Number()));
6292 6330
6293 obj->set_buffer(*buffer); 6331 SetupArrayBufferView(
6332 isolate, obj, buffer, byte_offset, length * sizeof(ElementType));
6294 6333
6295 obj->set_weak_next(buffer->weak_first_view()); 6334 i::Handle<i::Object> length_object =
6296 buffer->set_weak_first_view(*obj); 6335 isolate->factory()->NewNumberFromSize(length);
6297
6298 i::Handle<i::Object> byte_offset_object = isolate->factory()->NewNumber(
6299 static_cast<double>(byte_offset));
6300 obj->set_byte_offset(*byte_offset_object);
6301
6302 i::Handle<i::Object> byte_length_object = isolate->factory()->NewNumber(
6303 static_cast<double>(length * sizeof(ElementType)));
6304 obj->set_byte_length(*byte_length_object);
6305
6306 i::Handle<i::Object> length_object = isolate->factory()->NewNumber(
6307 static_cast<double>(length));
6308 obj->set_length(*length_object); 6336 obj->set_length(*length_object);
6309 6337
6310 i::Handle<i::ExternalArray> elements = 6338 i::Handle<i::ExternalArray> elements =
6311 isolate->factory()->NewExternalArray( 6339 isolate->factory()->NewExternalArray(
6312 static_cast<int>(length), array_type, 6340 static_cast<int>(length), array_type,
6313 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); 6341 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset);
6314 obj->set_elements(*elements); 6342 obj->set_elements(*elements);
6315 return obj; 6343 return obj;
6316 } 6344 }
6317 6345
(...skipping 28 matching lines...) Expand all
6346 i::EXTERNAL_UNSIGNED_INT_ELEMENTS) 6374 i::EXTERNAL_UNSIGNED_INT_ELEMENTS)
6347 TYPED_ARRAY_NEW(Int32Array, int32_t, kExternalIntArray, 6375 TYPED_ARRAY_NEW(Int32Array, int32_t, kExternalIntArray,
6348 i::EXTERNAL_INT_ELEMENTS) 6376 i::EXTERNAL_INT_ELEMENTS)
6349 TYPED_ARRAY_NEW(Float32Array, float, kExternalFloatArray, 6377 TYPED_ARRAY_NEW(Float32Array, float, kExternalFloatArray,
6350 i::EXTERNAL_FLOAT_ELEMENTS) 6378 i::EXTERNAL_FLOAT_ELEMENTS)
6351 TYPED_ARRAY_NEW(Float64Array, double, kExternalDoubleArray, 6379 TYPED_ARRAY_NEW(Float64Array, double, kExternalDoubleArray,
6352 i::EXTERNAL_DOUBLE_ELEMENTS) 6380 i::EXTERNAL_DOUBLE_ELEMENTS)
6353 6381
6354 #undef TYPED_ARRAY_NEW 6382 #undef TYPED_ARRAY_NEW
6355 6383
6384 Local<DataView> DataView::New(Handle<ArrayBuffer> array_buffer,
6385 size_t byte_offset, size_t byte_length) {
6386 i::Isolate* isolate = i::Isolate::Current();
6387 EnsureInitializedForIsolate(
6388 isolate, "v8::DataView::New(void*, size_t, size_t)");
6389 LOG_API(isolate, "v8::DataView::New(void*, size_t. size_t)");
Sven Panne 2013/06/24 08:17:54 Nit: comma instead of dot in the message?
6390 ENTER_V8(isolate);
6391 i::Handle<i::JSDataView> obj = isolate->factory()->NewJSDataView();
6392 i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer);
6393 SetupArrayBufferView(
6394 isolate, obj, buffer, byte_offset, byte_length);
6395 return Utils::ToLocal(obj);
6396 }
6397
6356 6398
6357 Local<Symbol> v8::Symbol::New(Isolate* isolate) { 6399 Local<Symbol> v8::Symbol::New(Isolate* isolate) {
6358 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 6400 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6359 EnsureInitializedForIsolate(i_isolate, "v8::Symbol::New()"); 6401 EnsureInitializedForIsolate(i_isolate, "v8::Symbol::New()");
6360 LOG_API(i_isolate, "Symbol::New()"); 6402 LOG_API(i_isolate, "Symbol::New()");
6361 ENTER_V8(i_isolate); 6403 ENTER_V8(i_isolate);
6362 i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol(); 6404 i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol();
6363 return Utils::ToLocal(result); 6405 return Utils::ToLocal(result);
6364 } 6406 }
6365 6407
(...skipping 1550 matching lines...) Expand 10 before | Expand all | Expand 10 after
7916 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7958 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7917 Address callback_address = 7959 Address callback_address =
7918 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7960 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7919 VMState<EXTERNAL> state(isolate); 7961 VMState<EXTERNAL> state(isolate);
7920 ExternalCallbackScope call_scope(isolate, callback_address); 7962 ExternalCallbackScope call_scope(isolate, callback_address);
7921 return callback(info); 7963 return callback(info);
7922 } 7964 }
7923 7965
7924 7966
7925 } } // namespace v8::internal 7967 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/api.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698