OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1440 num = i::Execution::ToInteger(obj, &has_pending_exception); | 1440 num = i::Execution::ToInteger(obj, &has_pending_exception); |
1441 EXCEPTION_BAILOUT_CHECK(Local<Integer>()); | 1441 EXCEPTION_BAILOUT_CHECK(Local<Integer>()); |
1442 } | 1442 } |
1443 return Local<Integer>(ToApi<Integer>(num)); | 1443 return Local<Integer>(ToApi<Integer>(num)); |
1444 } | 1444 } |
1445 | 1445 |
1446 | 1446 |
1447 External* External::Cast(v8::Value* that) { | 1447 External* External::Cast(v8::Value* that) { |
1448 if (IsDeadCheck("v8::External::Cast()")) return 0; | 1448 if (IsDeadCheck("v8::External::Cast()")) return 0; |
1449 i::Handle<i::Object> obj = Utils::OpenHandle(that); | 1449 i::Handle<i::Object> obj = Utils::OpenHandle(that); |
1450 ApiCheck(obj->IsProxy() || obj->IsSmi(), | 1450 ApiCheck(obj->IsProxy(), |
1451 "v8::External::Cast()", | 1451 "v8::External::Cast()", |
1452 "Could not convert to external"); | 1452 "Could not convert to external"); |
1453 return static_cast<External*>(that); | 1453 return static_cast<External*>(that); |
1454 } | 1454 } |
1455 | 1455 |
1456 | 1456 |
1457 v8::Object* v8::Object::Cast(Value* that) { | 1457 v8::Object* v8::Object::Cast(Value* that) { |
1458 if (IsDeadCheck("v8::Object::Cast()")) return 0; | 1458 if (IsDeadCheck("v8::Object::Cast()")) return 0; |
1459 i::Handle<i::Object> obj = Utils::OpenHandle(that); | 1459 i::Handle<i::Object> obj = Utils::OpenHandle(that); |
1460 ApiCheck(obj->IsJSObject(), | 1460 ApiCheck(obj->IsJSObject(), |
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2219 if (IsDeadCheck("v8::Int32::Value()")) return 0; | 2219 if (IsDeadCheck("v8::Int32::Value()")) return 0; |
2220 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 2220 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
2221 if (obj->IsSmi()) { | 2221 if (obj->IsSmi()) { |
2222 return i::Smi::cast(*obj)->value(); | 2222 return i::Smi::cast(*obj)->value(); |
2223 } else { | 2223 } else { |
2224 return static_cast<int32_t>(obj->Number()); | 2224 return static_cast<int32_t>(obj->Number()); |
2225 } | 2225 } |
2226 } | 2226 } |
2227 | 2227 |
2228 | 2228 |
2229 void* External::Value() const { | |
2230 if (IsDeadCheck("v8::External::Value()")) return 0; | |
2231 i::Handle<i::Object> obj = Utils::OpenHandle(this); | |
2232 if (obj->IsSmi()) { | |
2233 // The external value was an aligned pointer. | |
2234 return reinterpret_cast<void*>( | |
2235 i::Smi::cast(*obj)->value() << kAlignedPointerShift); | |
2236 } | |
2237 return reinterpret_cast<void*>(i::Proxy::cast(*obj)->proxy()); | |
2238 } | |
2239 | |
2240 | |
2241 int v8::Object::InternalFieldCount() { | 2229 int v8::Object::InternalFieldCount() { |
2242 if (IsDeadCheck("v8::Object::InternalFieldCount()")) return 0; | 2230 if (IsDeadCheck("v8::Object::InternalFieldCount()")) return 0; |
2243 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); | 2231 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
2244 return obj->GetInternalFieldCount(); | 2232 return obj->GetInternalFieldCount(); |
2245 } | 2233 } |
2246 | 2234 |
2247 | 2235 |
2248 Local<Value> v8::Object::GetInternalField(int index) { | 2236 Local<Value> v8::Object::GetInternalField(int index) { |
2249 if (IsDeadCheck("v8::Object::GetInternalField()")) return Local<Value>(); | 2237 if (IsDeadCheck("v8::Object::GetInternalField()")) return Local<Value>(); |
2250 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); | 2238 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2461 } | 2449 } |
2462 | 2450 |
2463 | 2451 |
2464 bool FunctionTemplate::HasInstance(v8::Handle<v8::Value> value) { | 2452 bool FunctionTemplate::HasInstance(v8::Handle<v8::Value> value) { |
2465 ON_BAILOUT("v8::FunctionTemplate::HasInstanceOf()", return false); | 2453 ON_BAILOUT("v8::FunctionTemplate::HasInstanceOf()", return false); |
2466 i::Object* obj = *Utils::OpenHandle(*value); | 2454 i::Object* obj = *Utils::OpenHandle(*value); |
2467 return obj->IsInstanceOf(*Utils::OpenHandle(this)); | 2455 return obj->IsInstanceOf(*Utils::OpenHandle(this)); |
2468 } | 2456 } |
2469 | 2457 |
2470 | 2458 |
| 2459 static Local<External> ExternalNewImpl(void* data) { |
| 2460 return Utils::ToLocal(i::Factory::NewProxy(static_cast<i::Address>(data))); |
| 2461 } |
| 2462 |
| 2463 static void* ExternalValueImpl(i::Handle<i::Object> obj) { |
| 2464 return reinterpret_cast<void*>(i::Proxy::cast(*obj)->proxy()); |
| 2465 } |
| 2466 |
| 2467 |
| 2468 static const intptr_t kAlignedPointerMask = 3; |
| 2469 static const int kAlignedPointerShift = 2; |
| 2470 |
| 2471 |
| 2472 Local<Value> v8::External::Wrap(void* data) { |
| 2473 STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); |
| 2474 LOG_API("External::Wrap"); |
| 2475 EnsureInitialized("v8::External::Wrap()"); |
| 2476 if ((reinterpret_cast<intptr_t>(data) & kAlignedPointerMask) == 0) { |
| 2477 uintptr_t data_ptr = reinterpret_cast<uintptr_t>(data); |
| 2478 int data_value = static_cast<int>(data_ptr >> kAlignedPointerShift); |
| 2479 STATIC_ASSERT(sizeof(data_ptr) == sizeof(data_value)); |
| 2480 i::Handle<i::Object> obj(i::Smi::FromInt(data_value)); |
| 2481 return Utils::ToLocal(obj); |
| 2482 } |
| 2483 return ExternalNewImpl(data); |
| 2484 } |
| 2485 |
| 2486 |
| 2487 void* v8::External::Unwrap(v8::Handle<v8::Value> value) { |
| 2488 if (IsDeadCheck("v8::External::Unwrap()")) return 0; |
| 2489 i::Handle<i::Object> obj = Utils::OpenHandle(*value); |
| 2490 if (obj->IsSmi()) { |
| 2491 // The external value was an aligned pointer. |
| 2492 uintptr_t result = i::Smi::cast(*obj)->value() << kAlignedPointerShift; |
| 2493 return reinterpret_cast<void*>(result); |
| 2494 } |
| 2495 return ExternalValueImpl(obj); |
| 2496 } |
| 2497 |
| 2498 |
2471 Local<External> v8::External::New(void* data) { | 2499 Local<External> v8::External::New(void* data) { |
2472 STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); | 2500 STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); |
2473 LOG_API("External::New"); | 2501 LOG_API("External::New"); |
2474 EnsureInitialized("v8::External::New()"); | 2502 EnsureInitialized("v8::External::New()"); |
2475 if ((reinterpret_cast<intptr_t>(data) & kAlignedPointerMask) == 0) { | 2503 return ExternalNewImpl(data); |
2476 uintptr_t data_ptr = reinterpret_cast<uintptr_t>(data); | 2504 } |
2477 int data_value = static_cast<int>(data_ptr >> kAlignedPointerShift); | 2505 |
2478 STATIC_ASSERT(sizeof(data_ptr) == sizeof(data_value)); | 2506 |
2479 i::Handle<i::Smi> obj(i::Smi::FromInt(data_value)); | 2507 void* External::Value() const { |
2480 return Utils::ToLocal(obj); | 2508 if (IsDeadCheck("v8::External::Value()")) return 0; |
2481 } | 2509 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
2482 return Utils::ToLocal(i::Factory::NewProxy(static_cast<i::Address>(data))); | 2510 return ExternalValueImpl(obj); |
2483 } | 2511 } |
2484 | 2512 |
2485 | 2513 |
2486 Local<String> v8::String::Empty() { | 2514 Local<String> v8::String::Empty() { |
2487 EnsureInitialized("v8::String::Empty()"); | 2515 EnsureInitialized("v8::String::Empty()"); |
2488 LOG_API("String::Empty()"); | 2516 LOG_API("String::Empty()"); |
2489 return Utils::ToLocal(i::Factory::empty_symbol()); | 2517 return Utils::ToLocal(i::Factory::empty_symbol()); |
2490 } | 2518 } |
2491 | 2519 |
2492 | 2520 |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3164 reinterpret_cast<HandleScopeImplementer*>(storage); | 3192 reinterpret_cast<HandleScopeImplementer*>(storage); |
3165 List<void**>* blocks_of_archived_thread = thread_local->Blocks(); | 3193 List<void**>* blocks_of_archived_thread = thread_local->Blocks(); |
3166 v8::ImplementationUtilities::HandleScopeData* handle_data_of_archived_thread = | 3194 v8::ImplementationUtilities::HandleScopeData* handle_data_of_archived_thread = |
3167 &thread_local->handle_scope_data_; | 3195 &thread_local->handle_scope_data_; |
3168 Iterate(v, blocks_of_archived_thread, handle_data_of_archived_thread); | 3196 Iterate(v, blocks_of_archived_thread, handle_data_of_archived_thread); |
3169 | 3197 |
3170 return storage + ArchiveSpacePerThread(); | 3198 return storage + ArchiveSpacePerThread(); |
3171 } | 3199 } |
3172 | 3200 |
3173 } } // namespace v8::internal | 3201 } } // namespace v8::internal |
OLD | NEW |