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

Side by Side Diff: src/api.cc

Issue 13977018: Add Value::Is* methods for typed arrays and ArrayBuffer (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 7 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 | « include/v8.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 2389 matching lines...) Expand 10 before | Expand all | Expand 10 after
2400 bool Value::IsSymbol() const { 2400 bool Value::IsSymbol() const {
2401 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsSymbol()")) return false; 2401 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsSymbol()")) return false;
2402 return Utils::OpenHandle(this)->IsSymbol(); 2402 return Utils::OpenHandle(this)->IsSymbol();
2403 } 2403 }
2404 2404
2405 2405
2406 bool Value::IsArray() const { 2406 bool Value::IsArray() const {
2407 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArray()")) return false; 2407 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArray()")) return false;
2408 return Utils::OpenHandle(this)->IsJSArray(); 2408 return Utils::OpenHandle(this)->IsJSArray();
2409 } 2409 }
2410 2410
rossberg 2013/04/30 13:46:48 Nit: extra line
2411 bool Value::IsArrayBuffer() const {
2412 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArrayBuffer()"))
2413 return false;
2414 return Utils::OpenHandle(this)->IsJSArrayBuffer();
2415 }
2416
2417
2418 bool Value::IsTypedArray() const {
2419 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArrayBuffer()"))
2420 return false;
2421 return Utils::OpenHandle(this)->IsJSTypedArray();
2422 }
2423
rossberg 2013/04/30 13:46:48 Same here
2424 #define TYPED_ARRAY_LIST(F) \
2425 F(Uint8Array, kExternalUnsignedByteArray) \
2426 F(Int8Array, kExternalByteArray) \
2427 F(Uint16Array, kExternalUnsignedShortArray) \
2428 F(Int16Array, kExternalShortArray) \
2429 F(Uint32Array, kExternalUnsignedIntArray) \
2430 F(Int32Array, kExternalIntArray) \
2431 F(Float32Array, kExternalFloatArray) \
2432 F(Float64Array, kExternalDoubleArray)
2433
2434
2435 #define VALUE_IS_TYPED_ARRAY(TypedArray, type_const) \
2436 bool Value::Is##TypedArray() const { \
2437 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::Is" #TypedArray "()")) \
2438 return false; \
2439 i::Handle<i::Object> obj = Utils::OpenHandle(this); \
2440 if (!obj->IsJSTypedArray()) return false; \
2441 return i::JSTypedArray::cast(*obj)->type() == type_const; \
2442 }
2443
2444 TYPED_ARRAY_LIST(VALUE_IS_TYPED_ARRAY)
2445
2446 #undef VALUE_IS_TYPED_ARRAY
2447
2411 2448
2412 bool Value::IsObject() const { 2449 bool Value::IsObject() const {
2413 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsObject()")) return false; 2450 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsObject()")) return false;
2414 return Utils::OpenHandle(this)->IsJSObject(); 2451 return Utils::OpenHandle(this)->IsJSObject();
2415 } 2452 }
2416 2453
2417 2454
2418 bool Value::IsNumber() const { 2455 bool Value::IsNumber() const {
2419 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsNumber()")) return false; 2456 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsNumber()")) return false;
2420 return Utils::OpenHandle(this)->IsNumber(); 2457 return Utils::OpenHandle(this)->IsNumber();
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
2769 if (IsDeadCheck(i::Isolate::Current(), "v8::" #ApiClass "::Cast()")) \ 2806 if (IsDeadCheck(i::Isolate::Current(), "v8::" #ApiClass "::Cast()")) \
2770 return; \ 2807 return; \
2771 i::Handle<i::Object> obj = Utils::OpenHandle(that); \ 2808 i::Handle<i::Object> obj = Utils::OpenHandle(that); \
2772 ApiCheck(obj->IsJSTypedArray() && \ 2809 ApiCheck(obj->IsJSTypedArray() && \
2773 i::JSTypedArray::cast(*obj)->type() == typeConst, \ 2810 i::JSTypedArray::cast(*obj)->type() == typeConst, \
2774 "v8::" #ApiClass "::Cast()", \ 2811 "v8::" #ApiClass "::Cast()", \
2775 "Could not convert to " #ApiClass); \ 2812 "Could not convert to " #ApiClass); \
2776 } 2813 }
2777 2814
2778 2815
2779 CHECK_TYPED_ARRAY_CAST(Uint8Array, kExternalUnsignedByteArray) 2816 TYPED_ARRAY_LIST(CHECK_TYPED_ARRAY_CAST)
2780 CHECK_TYPED_ARRAY_CAST(Int8Array, kExternalByteArray)
2781 CHECK_TYPED_ARRAY_CAST(Uint16Array, kExternalUnsignedShortArray)
2782 CHECK_TYPED_ARRAY_CAST(Int16Array, kExternalShortArray)
2783 CHECK_TYPED_ARRAY_CAST(Uint32Array, kExternalUnsignedIntArray)
2784 CHECK_TYPED_ARRAY_CAST(Int32Array, kExternalIntArray)
2785 CHECK_TYPED_ARRAY_CAST(Float32Array, kExternalFloatArray)
2786 CHECK_TYPED_ARRAY_CAST(Float64Array, kExternalDoubleArray)
2787 2817
2788 #undef CHECK_TYPED_ARRAY_CAST 2818 #undef CHECK_TYPED_ARRAY_CAST
2789 2819
2790 2820
2791 void v8::Date::CheckCast(v8::Value* that) { 2821 void v8::Date::CheckCast(v8::Value* that) {
2792 i::Isolate* isolate = i::Isolate::Current(); 2822 i::Isolate* isolate = i::Isolate::Current();
2793 if (IsDeadCheck(isolate, "v8::Date::Cast()")) return; 2823 if (IsDeadCheck(isolate, "v8::Date::Cast()")) return;
2794 i::Handle<i::Object> obj = Utils::OpenHandle(that); 2824 i::Handle<i::Object> obj = Utils::OpenHandle(that);
2795 ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Date_string()), 2825 ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Date_string()),
2796 "v8::Date::Cast()", 2826 "v8::Date::Cast()",
(...skipping 4838 matching lines...) Expand 10 before | Expand all | Expand 10 after
7635 7665
7636 v->VisitPointers(blocks_.first(), first_block_limit_); 7666 v->VisitPointers(blocks_.first(), first_block_limit_);
7637 7667
7638 for (int i = 1; i < blocks_.length(); i++) { 7668 for (int i = 1; i < blocks_.length(); i++) {
7639 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); 7669 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]);
7640 } 7670 }
7641 } 7671 }
7642 7672
7643 7673
7644 } } // namespace v8::internal 7674 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698