| 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 23 matching lines...) Expand all Loading... |
| 34 #include "execution.h" | 34 #include "execution.h" |
| 35 #include "global-handles.h" | 35 #include "global-handles.h" |
| 36 #include "platform.h" | 36 #include "platform.h" |
| 37 #include "serialize.h" | 37 #include "serialize.h" |
| 38 #include "snapshot.h" | 38 #include "snapshot.h" |
| 39 #include "v8threads.h" | 39 #include "v8threads.h" |
| 40 | 40 |
| 41 | 41 |
| 42 #define LOG_API(expr) LOG(ApiEntryCall(expr)) | 42 #define LOG_API(expr) LOG(ApiEntryCall(expr)) |
| 43 | 43 |
| 44 #ifdef ENABLE_HEAP_PROTECTION |
| 45 #define ENTER_V8 i::VMState __state__(i::OTHER) |
| 46 #else |
| 47 #define ENTER_V8 ((void) 0) |
| 48 #endif |
| 49 |
| 44 | 50 |
| 45 namespace v8 { | 51 namespace v8 { |
| 46 | 52 |
| 47 | 53 |
| 48 #define ON_BAILOUT(location, code) \ | 54 #define ON_BAILOUT(location, code) \ |
| 49 if (IsDeadCheck(location)) { \ | 55 if (IsDeadCheck(location)) { \ |
| 50 code; \ | 56 code; \ |
| 51 UNREACHABLE(); \ | 57 UNREACHABLE(); \ |
| 52 } | 58 } |
| 53 | 59 |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 | 458 |
| 453 // --- N e a n d e r --- | 459 // --- N e a n d e r --- |
| 454 | 460 |
| 455 | 461 |
| 456 // A constructor cannot easily return an error value, therefore it is necessary | 462 // A constructor cannot easily return an error value, therefore it is necessary |
| 457 // to check for a dead VM with ON_BAILOUT before constructing any Neander | 463 // to check for a dead VM with ON_BAILOUT before constructing any Neander |
| 458 // objects. To remind you about this there is no HandleScope in the | 464 // objects. To remind you about this there is no HandleScope in the |
| 459 // NeanderObject constructor. When you add one to the site calling the | 465 // NeanderObject constructor. When you add one to the site calling the |
| 460 // constructor you should check that you ensured the VM was not dead first. | 466 // constructor you should check that you ensured the VM was not dead first. |
| 461 NeanderObject::NeanderObject(int size) { | 467 NeanderObject::NeanderObject(int size) { |
| 468 ENTER_V8; |
| 462 EnsureInitialized("v8::Nowhere"); | 469 EnsureInitialized("v8::Nowhere"); |
| 463 value_ = i::Factory::NewNeanderObject(); | 470 value_ = i::Factory::NewNeanderObject(); |
| 464 i::Handle<i::FixedArray> elements = i::Factory::NewFixedArray(size); | 471 i::Handle<i::FixedArray> elements = i::Factory::NewFixedArray(size); |
| 465 value_->set_elements(*elements); | 472 value_->set_elements(*elements); |
| 466 } | 473 } |
| 467 | 474 |
| 468 | 475 |
| 469 int NeanderObject::size() { | 476 int NeanderObject::size() { |
| 470 return i::FixedArray::cast(value_->elements())->length(); | 477 return i::FixedArray::cast(value_->elements())->length(); |
| 471 } | 478 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 // --- T e m p l a t e --- | 523 // --- T e m p l a t e --- |
| 517 | 524 |
| 518 | 525 |
| 519 static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) { | 526 static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) { |
| 520 that->set_tag(i::Smi::FromInt(type)); | 527 that->set_tag(i::Smi::FromInt(type)); |
| 521 } | 528 } |
| 522 | 529 |
| 523 | 530 |
| 524 void Template::Set(v8::Handle<String> name, v8::Handle<Data> value, | 531 void Template::Set(v8::Handle<String> name, v8::Handle<Data> value, |
| 525 v8::PropertyAttribute attribute) { | 532 v8::PropertyAttribute attribute) { |
| 533 ENTER_V8; |
| 526 if (IsDeadCheck("v8::Template::SetProperty()")) return; | 534 if (IsDeadCheck("v8::Template::SetProperty()")) return; |
| 527 HandleScope scope; | 535 HandleScope scope; |
| 528 i::Handle<i::Object> list(Utils::OpenHandle(this)->property_list()); | 536 i::Handle<i::Object> list(Utils::OpenHandle(this)->property_list()); |
| 529 if (list->IsUndefined()) { | 537 if (list->IsUndefined()) { |
| 530 list = NeanderArray().value(); | 538 list = NeanderArray().value(); |
| 531 Utils::OpenHandle(this)->set_property_list(*list); | 539 Utils::OpenHandle(this)->set_property_list(*list); |
| 532 } | 540 } |
| 533 NeanderArray array(list); | 541 NeanderArray array(list); |
| 534 array.add(Utils::OpenHandle(*name)); | 542 array.add(Utils::OpenHandle(*name)); |
| 535 array.add(Utils::OpenHandle(*value)); | 543 array.add(Utils::OpenHandle(*value)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 564 } | 572 } |
| 565 | 573 |
| 566 | 574 |
| 567 // To distinguish the function templates, so that we can find them in the | 575 // To distinguish the function templates, so that we can find them in the |
| 568 // function cache of the global context. | 576 // function cache of the global context. |
| 569 static int next_serial_number = 0; | 577 static int next_serial_number = 0; |
| 570 | 578 |
| 571 | 579 |
| 572 Local<FunctionTemplate> FunctionTemplate::New(InvocationCallback callback, | 580 Local<FunctionTemplate> FunctionTemplate::New(InvocationCallback callback, |
| 573 v8::Handle<Value> data, v8::Handle<Signature> signature) { | 581 v8::Handle<Value> data, v8::Handle<Signature> signature) { |
| 582 ENTER_V8; |
| 574 EnsureInitialized("v8::FunctionTemplate::New()"); | 583 EnsureInitialized("v8::FunctionTemplate::New()"); |
| 575 LOG_API("FunctionTemplate::New"); | 584 LOG_API("FunctionTemplate::New"); |
| 576 i::Handle<i::Struct> struct_obj = | 585 i::Handle<i::Struct> struct_obj = |
| 577 i::Factory::NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); | 586 i::Factory::NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); |
| 578 i::Handle<i::FunctionTemplateInfo> obj = | 587 i::Handle<i::FunctionTemplateInfo> obj = |
| 579 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); | 588 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); |
| 580 InitializeFunctionTemplate(obj); | 589 InitializeFunctionTemplate(obj); |
| 581 obj->set_serial_number(i::Smi::FromInt(next_serial_number++)); | 590 obj->set_serial_number(i::Smi::FromInt(next_serial_number++)); |
| 582 if (callback != 0) { | 591 if (callback != 0) { |
| 583 if (data.IsEmpty()) data = v8::Undefined(); | 592 if (data.IsEmpty()) data = v8::Undefined(); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 // --- O b j e c t T e m p l a t e --- | 805 // --- O b j e c t T e m p l a t e --- |
| 797 | 806 |
| 798 | 807 |
| 799 Local<ObjectTemplate> ObjectTemplate::New() { | 808 Local<ObjectTemplate> ObjectTemplate::New() { |
| 800 return New(Local<FunctionTemplate>()); | 809 return New(Local<FunctionTemplate>()); |
| 801 } | 810 } |
| 802 | 811 |
| 803 | 812 |
| 804 Local<ObjectTemplate> ObjectTemplate::New( | 813 Local<ObjectTemplate> ObjectTemplate::New( |
| 805 v8::Handle<FunctionTemplate> constructor) { | 814 v8::Handle<FunctionTemplate> constructor) { |
| 815 ENTER_V8; |
| 806 if (IsDeadCheck("v8::ObjectTemplate::New()")) return Local<ObjectTemplate>(); | 816 if (IsDeadCheck("v8::ObjectTemplate::New()")) return Local<ObjectTemplate>(); |
| 807 EnsureInitialized("v8::ObjectTemplate::New()"); | 817 EnsureInitialized("v8::ObjectTemplate::New()"); |
| 808 LOG_API("ObjectTemplate::New"); | 818 LOG_API("ObjectTemplate::New"); |
| 809 i::Handle<i::Struct> struct_obj = | 819 i::Handle<i::Struct> struct_obj = |
| 810 i::Factory::NewStruct(i::OBJECT_TEMPLATE_INFO_TYPE); | 820 i::Factory::NewStruct(i::OBJECT_TEMPLATE_INFO_TYPE); |
| 811 i::Handle<i::ObjectTemplateInfo> obj = | 821 i::Handle<i::ObjectTemplateInfo> obj = |
| 812 i::Handle<i::ObjectTemplateInfo>::cast(struct_obj); | 822 i::Handle<i::ObjectTemplateInfo>::cast(struct_obj); |
| 813 InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); | 823 InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); |
| 814 if (!constructor.IsEmpty()) | 824 if (!constructor.IsEmpty()) |
| 815 obj->set_constructor(*Utils::OpenHandle(*constructor)); | 825 obj->set_constructor(*Utils::OpenHandle(*constructor)); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 return new i::ScriptDataImpl(i::Vector<unsigned>(data, length)); | 991 return new i::ScriptDataImpl(i::Vector<unsigned>(data, length)); |
| 982 } | 992 } |
| 983 | 993 |
| 984 | 994 |
| 985 // --- S c r i p t --- | 995 // --- S c r i p t --- |
| 986 | 996 |
| 987 | 997 |
| 988 Local<Script> Script::Compile(v8::Handle<String> source, | 998 Local<Script> Script::Compile(v8::Handle<String> source, |
| 989 v8::ScriptOrigin* origin, | 999 v8::ScriptOrigin* origin, |
| 990 v8::ScriptData* script_data) { | 1000 v8::ScriptData* script_data) { |
| 1001 ENTER_V8; |
| 991 ON_BAILOUT("v8::Script::Compile()", return Local<Script>()); | 1002 ON_BAILOUT("v8::Script::Compile()", return Local<Script>()); |
| 992 LOG_API("Script::Compile"); | 1003 LOG_API("Script::Compile"); |
| 993 i::Handle<i::String> str = Utils::OpenHandle(*source); | 1004 i::Handle<i::String> str = Utils::OpenHandle(*source); |
| 994 i::Handle<i::Object> name_obj; | 1005 i::Handle<i::Object> name_obj; |
| 995 int line_offset = 0; | 1006 int line_offset = 0; |
| 996 int column_offset = 0; | 1007 int column_offset = 0; |
| 997 if (origin != NULL) { | 1008 if (origin != NULL) { |
| 998 if (!origin->ResourceName().IsEmpty()) { | 1009 if (!origin->ResourceName().IsEmpty()) { |
| 999 name_obj = Utils::OpenHandle(*origin->ResourceName()); | 1010 name_obj = Utils::OpenHandle(*origin->ResourceName()); |
| 1000 } | 1011 } |
| (...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2255 return; | 2266 return; |
| 2256 } | 2267 } |
| 2257 i::Handle<i::Object> val = Utils::OpenHandle(*value); | 2268 i::Handle<i::Object> val = Utils::OpenHandle(*value); |
| 2258 obj->SetInternalField(index, *val); | 2269 obj->SetInternalField(index, *val); |
| 2259 } | 2270 } |
| 2260 | 2271 |
| 2261 | 2272 |
| 2262 // --- E n v i r o n m e n t --- | 2273 // --- E n v i r o n m e n t --- |
| 2263 | 2274 |
| 2264 bool v8::V8::Initialize() { | 2275 bool v8::V8::Initialize() { |
| 2276 ENTER_V8; |
| 2265 if (i::V8::HasBeenSetup()) return true; | 2277 if (i::V8::HasBeenSetup()) return true; |
| 2266 HandleScope scope; | 2278 HandleScope scope; |
| 2267 if (i::Snapshot::Initialize()) { | 2279 if (i::Snapshot::Initialize()) { |
| 2268 return true; | 2280 return true; |
| 2269 } else { | 2281 } else { |
| 2270 return i::V8::Initialize(NULL); | 2282 return i::V8::Initialize(NULL); |
| 2271 } | 2283 } |
| 2272 } | 2284 } |
| 2273 | 2285 |
| 2274 | 2286 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2292 } | 2304 } |
| 2293 return i::Handle<i::FunctionTemplateInfo>( | 2305 return i::Handle<i::FunctionTemplateInfo>( |
| 2294 i::FunctionTemplateInfo::cast(templ->constructor())); | 2306 i::FunctionTemplateInfo::cast(templ->constructor())); |
| 2295 } | 2307 } |
| 2296 | 2308 |
| 2297 | 2309 |
| 2298 Persistent<Context> v8::Context::New( | 2310 Persistent<Context> v8::Context::New( |
| 2299 v8::ExtensionConfiguration* extensions, | 2311 v8::ExtensionConfiguration* extensions, |
| 2300 v8::Handle<ObjectTemplate> global_template, | 2312 v8::Handle<ObjectTemplate> global_template, |
| 2301 v8::Handle<Value> global_object) { | 2313 v8::Handle<Value> global_object) { |
| 2314 ENTER_V8; |
| 2302 EnsureInitialized("v8::Context::New()"); | 2315 EnsureInitialized("v8::Context::New()"); |
| 2303 LOG_API("Context::New"); | 2316 LOG_API("Context::New"); |
| 2304 ON_BAILOUT("v8::Context::New()", return Persistent<Context>()); | 2317 ON_BAILOUT("v8::Context::New()", return Persistent<Context>()); |
| 2305 | 2318 |
| 2306 // Give the heap a chance to cleanup if we've disposed contexts. | 2319 // Give the heap a chance to cleanup if we've disposed contexts. |
| 2307 i::Heap::CollectAllGarbageIfContextDisposed(); | 2320 i::Heap::CollectAllGarbageIfContextDisposed(); |
| 2308 | 2321 |
| 2309 v8::Handle<ObjectTemplate> proxy_template = global_template; | 2322 v8::Handle<ObjectTemplate> proxy_template = global_template; |
| 2310 i::Handle<i::FunctionTemplateInfo> proxy_constructor; | 2323 i::Handle<i::FunctionTemplateInfo> proxy_constructor; |
| 2311 i::Handle<i::FunctionTemplateInfo> global_constructor; | 2324 i::Handle<i::FunctionTemplateInfo> global_constructor; |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2518 | 2531 |
| 2519 | 2532 |
| 2520 Local<String> v8::String::Empty() { | 2533 Local<String> v8::String::Empty() { |
| 2521 EnsureInitialized("v8::String::Empty()"); | 2534 EnsureInitialized("v8::String::Empty()"); |
| 2522 LOG_API("String::Empty()"); | 2535 LOG_API("String::Empty()"); |
| 2523 return Utils::ToLocal(i::Factory::empty_symbol()); | 2536 return Utils::ToLocal(i::Factory::empty_symbol()); |
| 2524 } | 2537 } |
| 2525 | 2538 |
| 2526 | 2539 |
| 2527 Local<String> v8::String::New(const char* data, int length) { | 2540 Local<String> v8::String::New(const char* data, int length) { |
| 2541 ENTER_V8; |
| 2528 EnsureInitialized("v8::String::New()"); | 2542 EnsureInitialized("v8::String::New()"); |
| 2529 LOG_API("String::New(char)"); | 2543 LOG_API("String::New(char)"); |
| 2530 if (length == 0) return Empty(); | 2544 if (length == 0) return Empty(); |
| 2531 if (length == -1) length = strlen(data); | 2545 if (length == -1) length = strlen(data); |
| 2532 i::Handle<i::String> result = | 2546 i::Handle<i::String> result = |
| 2533 i::Factory::NewStringFromUtf8(i::Vector<const char>(data, length)); | 2547 i::Factory::NewStringFromUtf8(i::Vector<const char>(data, length)); |
| 2534 return Utils::ToLocal(result); | 2548 return Utils::ToLocal(result); |
| 2535 } | 2549 } |
| 2536 | 2550 |
| 2537 | 2551 |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3199 reinterpret_cast<HandleScopeImplementer*>(storage); | 3213 reinterpret_cast<HandleScopeImplementer*>(storage); |
| 3200 List<void**>* blocks_of_archived_thread = thread_local->Blocks(); | 3214 List<void**>* blocks_of_archived_thread = thread_local->Blocks(); |
| 3201 v8::ImplementationUtilities::HandleScopeData* handle_data_of_archived_thread = | 3215 v8::ImplementationUtilities::HandleScopeData* handle_data_of_archived_thread = |
| 3202 &thread_local->handle_scope_data_; | 3216 &thread_local->handle_scope_data_; |
| 3203 Iterate(v, blocks_of_archived_thread, handle_data_of_archived_thread); | 3217 Iterate(v, blocks_of_archived_thread, handle_data_of_archived_thread); |
| 3204 | 3218 |
| 3205 return storage + ArchiveSpacePerThread(); | 3219 return storage + ArchiveSpacePerThread(); |
| 3206 } | 3220 } |
| 3207 | 3221 |
| 3208 } } // namespace v8::internal | 3222 } } // namespace v8::internal |
| OLD | NEW |