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

Side by Side Diff: src/api.cc

Issue 464413002: Expose Value::IsMap, IsSet, IsWeakMap, IsWeakSet in V8 API. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 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') | src/heap/heap.h » ('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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 2365 matching lines...) Expand 10 before | Expand all | Expand 10 after
2376 bool Value::IsObject() const { 2376 bool Value::IsObject() const {
2377 return Utils::OpenHandle(this)->IsJSObject(); 2377 return Utils::OpenHandle(this)->IsJSObject();
2378 } 2378 }
2379 2379
2380 2380
2381 bool Value::IsNumber() const { 2381 bool Value::IsNumber() const {
2382 return Utils::OpenHandle(this)->IsNumber(); 2382 return Utils::OpenHandle(this)->IsNumber();
2383 } 2383 }
2384 2384
2385 2385
2386 bool Value::IsArgumentsObject() const { 2386 #define VALUE_IS_SPECIFIC_TYPE(Type, Class) \
2387 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2387 bool Value::Is##Type() const { \
2388 if (!obj->IsHeapObject()) return false; 2388 i::Handle<i::Object> obj = Utils::OpenHandle(this); \
2389 i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate(); 2389 if (!obj->IsHeapObject()) return false; \
2390 return obj->HasSpecificClassOf(isolate->heap()->Arguments_string()); 2390 i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate(); \
2391 } 2391 return obj->HasSpecificClassOf(isolate->heap()->Class##_string()); \
2392 }
2393
2394 VALUE_IS_SPECIFIC_TYPE(ArgumentsObject, Arguments)
2395 VALUE_IS_SPECIFIC_TYPE(BooleanObject, Boolean)
2396 VALUE_IS_SPECIFIC_TYPE(NumberObject, Number)
2397 VALUE_IS_SPECIFIC_TYPE(StringObject, String)
2398 VALUE_IS_SPECIFIC_TYPE(SymbolObject, Symbol)
2399 VALUE_IS_SPECIFIC_TYPE(Date, Date)
2400 VALUE_IS_SPECIFIC_TYPE(Map, Map)
2401 VALUE_IS_SPECIFIC_TYPE(Set, Set)
2402 VALUE_IS_SPECIFIC_TYPE(WeakMap, WeakMap)
2403 VALUE_IS_SPECIFIC_TYPE(WeakSet, WeakSet)
2404
2405 #undef VALUE_IS_SPECIFIC_TYPE
2392 2406
2393 2407
2394 bool Value::IsBoolean() const { 2408 bool Value::IsBoolean() const {
2395 return Utils::OpenHandle(this)->IsBoolean(); 2409 return Utils::OpenHandle(this)->IsBoolean();
2396 } 2410 }
2397 2411
2398 2412
2399 bool Value::IsExternal() const { 2413 bool Value::IsExternal() const {
2400 return Utils::OpenHandle(this)->IsExternal(); 2414 return Utils::OpenHandle(this)->IsExternal();
2401 } 2415 }
(...skipping 16 matching lines...) Expand all
2418 double value = obj->Number(); 2432 double value = obj->Number();
2419 return !i::IsMinusZero(value) && 2433 return !i::IsMinusZero(value) &&
2420 value >= 0 && 2434 value >= 0 &&
2421 value <= i::kMaxUInt32 && 2435 value <= i::kMaxUInt32 &&
2422 value == i::FastUI2D(i::FastD2UI(value)); 2436 value == i::FastUI2D(i::FastD2UI(value));
2423 } 2437 }
2424 return false; 2438 return false;
2425 } 2439 }
2426 2440
2427 2441
2428 bool Value::IsDate() const {
2429 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2430 if (!obj->IsHeapObject()) return false;
2431 i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
2432 return obj->HasSpecificClassOf(isolate->heap()->Date_string());
2433 }
2434
2435
2436 bool Value::IsStringObject() const {
2437 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2438 if (!obj->IsHeapObject()) return false;
2439 i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
2440 return obj->HasSpecificClassOf(isolate->heap()->String_string());
2441 }
2442
2443
2444 bool Value::IsSymbolObject() const {
2445 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2446 if (!obj->IsHeapObject()) return false;
2447 i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
2448 return obj->HasSpecificClassOf(isolate->heap()->Symbol_string());
2449 }
2450
2451
2452 bool Value::IsNumberObject() const {
2453 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2454 if (!obj->IsHeapObject()) return false;
2455 i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
2456 return obj->HasSpecificClassOf(isolate->heap()->Number_string());
2457 }
2458
2459
2460 static bool CheckConstructor(i::Isolate* isolate, 2442 static bool CheckConstructor(i::Isolate* isolate,
2461 i::Handle<i::JSObject> obj, 2443 i::Handle<i::JSObject> obj,
2462 const char* class_name) { 2444 const char* class_name) {
2463 i::Handle<i::Object> constr(obj->map()->constructor(), isolate); 2445 i::Handle<i::Object> constr(obj->map()->constructor(), isolate);
2464 if (!constr->IsJSFunction()) return false; 2446 if (!constr->IsJSFunction()) return false;
2465 i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast(constr); 2447 i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast(constr);
2466 return func->shared()->native() && constr.is_identical_to( 2448 return func->shared()->native() && constr.is_identical_to(
2467 i::Object::GetProperty(isolate, 2449 i::Object::GetProperty(isolate,
2468 isolate->js_builtins_object(), 2450 isolate->js_builtins_object(),
2469 class_name).ToHandleChecked()); 2451 class_name).ToHandleChecked());
(...skipping 11 matching lines...) Expand all
2481 CheckConstructor(isolate, js_obj, "$ReferenceError") || 2463 CheckConstructor(isolate, js_obj, "$ReferenceError") ||
2482 CheckConstructor(isolate, js_obj, "$SyntaxError") || 2464 CheckConstructor(isolate, js_obj, "$SyntaxError") ||
2483 CheckConstructor(isolate, js_obj, "$TypeError") || 2465 CheckConstructor(isolate, js_obj, "$TypeError") ||
2484 CheckConstructor(isolate, js_obj, "$URIError"); 2466 CheckConstructor(isolate, js_obj, "$URIError");
2485 } else { 2467 } else {
2486 return false; 2468 return false;
2487 } 2469 }
2488 } 2470 }
2489 2471
2490 2472
2491 bool Value::IsBooleanObject() const {
2492 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2493 if (!obj->IsHeapObject()) return false;
2494 i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
2495 return obj->HasSpecificClassOf(isolate->heap()->Boolean_string());
2496 }
2497
2498
2499 bool Value::IsRegExp() const { 2473 bool Value::IsRegExp() const {
2500 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2474 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2501 return obj->IsJSRegExp(); 2475 return obj->IsJSRegExp();
2502 } 2476 }
2503 2477
2504 2478
2505 Local<String> Value::ToString() const { 2479 Local<String> Value::ToString() const {
2506 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2480 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2507 i::Handle<i::Object> str; 2481 i::Handle<i::Object> str;
2508 if (obj->IsString()) { 2482 if (obj->IsString()) {
(...skipping 5130 matching lines...) Expand 10 before | Expand all | Expand 10 after
7639 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7613 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7640 Address callback_address = 7614 Address callback_address =
7641 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7615 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7642 VMState<EXTERNAL> state(isolate); 7616 VMState<EXTERNAL> state(isolate);
7643 ExternalCallbackScope call_scope(isolate, callback_address); 7617 ExternalCallbackScope call_scope(isolate, callback_address);
7644 callback(info); 7618 callback(info);
7645 } 7619 }
7646 7620
7647 7621
7648 } } // namespace v8::internal 7622 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/heap/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698