| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 29 matching lines...) Expand all Loading... |
| 40 #include "snapshot.h" | 40 #include "snapshot.h" |
| 41 #include "extensions/externalize-string-extension.h" | 41 #include "extensions/externalize-string-extension.h" |
| 42 #include "extensions/gc-extension.h" | 42 #include "extensions/gc-extension.h" |
| 43 | 43 |
| 44 namespace v8 { | 44 namespace v8 { |
| 45 namespace internal { | 45 namespace internal { |
| 46 | 46 |
| 47 | 47 |
| 48 NativesExternalStringResource::NativesExternalStringResource( | 48 NativesExternalStringResource::NativesExternalStringResource( |
| 49 Bootstrapper* bootstrapper, | 49 Bootstrapper* bootstrapper, |
| 50 const char* source) | 50 const char* source, |
| 51 : data_(source), length_(StrLength(source)) { | 51 size_t length) |
| 52 : data_(source), length_(length) { |
| 52 if (bootstrapper->delete_these_non_arrays_on_tear_down_ == NULL) { | 53 if (bootstrapper->delete_these_non_arrays_on_tear_down_ == NULL) { |
| 53 bootstrapper->delete_these_non_arrays_on_tear_down_ = new List<char*>(2); | 54 bootstrapper->delete_these_non_arrays_on_tear_down_ = new List<char*>(2); |
| 54 } | 55 } |
| 55 // The resources are small objects and we only make a fixed number of | 56 // The resources are small objects and we only make a fixed number of |
| 56 // them, but let's clean them up on exit for neatness. | 57 // them, but let's clean them up on exit for neatness. |
| 57 bootstrapper->delete_these_non_arrays_on_tear_down_-> | 58 bootstrapper->delete_these_non_arrays_on_tear_down_-> |
| 58 Add(reinterpret_cast<char*>(this)); | 59 Add(reinterpret_cast<char*>(this)); |
| 59 } | 60 } |
| 60 | 61 |
| 61 | 62 |
| 62 Bootstrapper::Bootstrapper() | 63 Bootstrapper::Bootstrapper() |
| 63 : nesting_(0), | 64 : nesting_(0), |
| 64 extensions_cache_(Script::TYPE_EXTENSION), | 65 extensions_cache_(Script::TYPE_EXTENSION), |
| 65 delete_these_non_arrays_on_tear_down_(NULL), | 66 delete_these_non_arrays_on_tear_down_(NULL), |
| 66 delete_these_arrays_on_tear_down_(NULL) { | 67 delete_these_arrays_on_tear_down_(NULL) { |
| 67 } | 68 } |
| 68 | 69 |
| 69 | 70 |
| 70 Handle<String> Bootstrapper::NativesSourceLookup(int index) { | 71 Handle<String> Bootstrapper::NativesSourceLookup(int index) { |
| 71 ASSERT(0 <= index && index < Natives::GetBuiltinsCount()); | 72 ASSERT(0 <= index && index < Natives::GetBuiltinsCount()); |
| 72 Isolate* isolate = Isolate::Current(); | 73 Isolate* isolate = Isolate::Current(); |
| 73 Factory* factory = isolate->factory(); | 74 Factory* factory = isolate->factory(); |
| 74 Heap* heap = isolate->heap(); | 75 Heap* heap = isolate->heap(); |
| 75 if (heap->natives_source_cache()->get(index)->IsUndefined()) { | 76 if (heap->natives_source_cache()->get(index)->IsUndefined()) { |
| 76 if (!Snapshot::IsEnabled() || FLAG_new_snapshot) { | 77 if (!Snapshot::IsEnabled() || FLAG_new_snapshot) { |
| 77 // We can use external strings for the natives. | 78 // We can use external strings for the natives. |
| 79 Vector<const char> source = Natives::GetRawScriptSource(index); |
| 78 NativesExternalStringResource* resource = | 80 NativesExternalStringResource* resource = |
| 79 new NativesExternalStringResource(this, | 81 new NativesExternalStringResource(this, |
| 80 Natives::GetScriptSource(index).start()); | 82 source.start(), |
| 83 source.length()); |
| 81 Handle<String> source_code = | 84 Handle<String> source_code = |
| 82 factory->NewExternalStringFromAscii(resource); | 85 factory->NewExternalStringFromAscii(resource); |
| 83 heap->natives_source_cache()->set(index, *source_code); | 86 heap->natives_source_cache()->set(index, *source_code); |
| 84 } else { | 87 } else { |
| 85 // Old snapshot code can't cope with external strings at all. | 88 // Old snapshot code can't cope with external strings at all. |
| 86 Handle<String> source_code = | 89 Handle<String> source_code = |
| 87 factory->NewStringFromAscii(Natives::GetScriptSource(index)); | 90 factory->NewStringFromAscii(Natives::GetRawScriptSource(index)); |
| 88 heap->natives_source_cache()->set(index, *source_code); | 91 heap->natives_source_cache()->set(index, *source_code); |
| 89 } | 92 } |
| 90 } | 93 } |
| 91 Handle<Object> cached_source(heap->natives_source_cache()->get(index)); | 94 Handle<Object> cached_source(heap->natives_source_cache()->get(index)); |
| 92 return Handle<String>::cast(cached_source); | 95 return Handle<String>::cast(cached_source); |
| 93 } | 96 } |
| 94 | 97 |
| 95 | 98 |
| 96 void Bootstrapper::Initialize(bool create_heap_objects) { | 99 void Bootstrapper::Initialize(bool create_heap_objects) { |
| 97 extensions_cache_.Initialize(create_heap_objects); | 100 extensions_cache_.Initialize(create_heap_objects); |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 } | 807 } |
| 805 | 808 |
| 806 | 809 |
| 807 // This is only called if we are not using snapshots. The equivalent | 810 // This is only called if we are not using snapshots. The equivalent |
| 808 // work in the snapshot case is done in HookUpInnerGlobal. | 811 // work in the snapshot case is done in HookUpInnerGlobal. |
| 809 void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, | 812 void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, |
| 810 Handle<JSFunction> empty_function) { | 813 Handle<JSFunction> empty_function) { |
| 811 // --- G l o b a l C o n t e x t --- | 814 // --- G l o b a l C o n t e x t --- |
| 812 // Use the empty function as closure (no scope info). | 815 // Use the empty function as closure (no scope info). |
| 813 global_context()->set_closure(*empty_function); | 816 global_context()->set_closure(*empty_function); |
| 814 global_context()->set_fcontext(*global_context()); | |
| 815 global_context()->set_previous(NULL); | 817 global_context()->set_previous(NULL); |
| 816 // Set extension and global object. | 818 // Set extension and global object. |
| 817 global_context()->set_extension(*inner_global); | 819 global_context()->set_extension(*inner_global); |
| 818 global_context()->set_global(*inner_global); | 820 global_context()->set_global(*inner_global); |
| 819 // Security setup: Set the security token of the global object to | 821 // Security setup: Set the security token of the global object to |
| 820 // its the inner global. This makes the security check between two | 822 // its the inner global. This makes the security check between two |
| 821 // different contexts fail by default even in case of global | 823 // different contexts fail by default even in case of global |
| 822 // object reinitialization. | 824 // object reinitialization. |
| 823 global_context()->set_security_token(*inner_global); | 825 global_context()->set_security_token(*inner_global); |
| 824 | 826 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 | 1047 |
| 1046 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsCalleeIndex); | 1048 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsCalleeIndex); |
| 1047 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsLengthIndex); | 1049 ASSERT(result->map()->inobject_properties() > Heap::kArgumentsLengthIndex); |
| 1048 | 1050 |
| 1049 // Check the state of the object. | 1051 // Check the state of the object. |
| 1050 ASSERT(result->HasFastProperties()); | 1052 ASSERT(result->HasFastProperties()); |
| 1051 ASSERT(result->HasFastElements()); | 1053 ASSERT(result->HasFastElements()); |
| 1052 #endif | 1054 #endif |
| 1053 } | 1055 } |
| 1054 | 1056 |
| 1057 { // --- aliased_arguments_boilerplate_ |
| 1058 Handle<Map> old_map(global_context()->arguments_boilerplate()->map()); |
| 1059 Handle<Map> new_map = factory->CopyMapDropTransitions(old_map); |
| 1060 new_map->set_pre_allocated_property_fields(2); |
| 1061 Handle<JSObject> result = factory->NewJSObjectFromMap(new_map); |
| 1062 new_map->set_elements_kind(JSObject::NON_STRICT_ARGUMENTS_ELEMENTS); |
| 1063 // Set up a well-formed parameter map to make assertions happy. |
| 1064 Handle<FixedArray> elements = factory->NewFixedArray(2); |
| 1065 elements->set_map(heap->non_strict_arguments_elements_map()); |
| 1066 Handle<FixedArray> array; |
| 1067 array = factory->NewFixedArray(0); |
| 1068 elements->set(0, *array); |
| 1069 array = factory->NewFixedArray(0); |
| 1070 elements->set(1, *array); |
| 1071 result->set_elements(*elements); |
| 1072 global_context()->set_aliased_arguments_boilerplate(*result); |
| 1073 } |
| 1074 |
| 1055 { // --- strict mode arguments boilerplate | 1075 { // --- strict mode arguments boilerplate |
| 1056 const PropertyAttributes attributes = | 1076 const PropertyAttributes attributes = |
| 1057 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 1077 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 1058 | 1078 |
| 1059 // Create the ThrowTypeError functions. | 1079 // Create the ThrowTypeError functions. |
| 1060 Handle<FixedArray> callee = factory->NewFixedArray(2, TENURED); | 1080 Handle<FixedArray> callee = factory->NewFixedArray(2, TENURED); |
| 1061 Handle<FixedArray> caller = factory->NewFixedArray(2, TENURED); | 1081 Handle<FixedArray> caller = factory->NewFixedArray(2, TENURED); |
| 1062 | 1082 |
| 1063 Handle<JSFunction> throw_function = | 1083 Handle<JSFunction> throw_function = |
| 1064 GetThrowTypeErrorFunction(); | 1084 GetThrowTypeErrorFunction(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1175 Handle<String> source_code = | 1195 Handle<String> source_code = |
| 1176 isolate->bootstrapper()->NativesSourceLookup(index); | 1196 isolate->bootstrapper()->NativesSourceLookup(index); |
| 1177 return CompileNative(name, source_code); | 1197 return CompileNative(name, source_code); |
| 1178 } | 1198 } |
| 1179 | 1199 |
| 1180 | 1200 |
| 1181 bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) { | 1201 bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) { |
| 1182 Vector<const char> name = ExperimentalNatives::GetScriptName(index); | 1202 Vector<const char> name = ExperimentalNatives::GetScriptName(index); |
| 1183 Factory* factory = isolate->factory(); | 1203 Factory* factory = isolate->factory(); |
| 1184 Handle<String> source_code = | 1204 Handle<String> source_code = |
| 1185 factory->NewStringFromAscii(ExperimentalNatives::GetScriptSource(index)); | 1205 factory->NewStringFromAscii( |
| 1206 ExperimentalNatives::GetRawScriptSource(index)); |
| 1186 return CompileNative(name, source_code); | 1207 return CompileNative(name, source_code); |
| 1187 } | 1208 } |
| 1188 | 1209 |
| 1189 | 1210 |
| 1190 bool Genesis::CompileNative(Vector<const char> name, Handle<String> source) { | 1211 bool Genesis::CompileNative(Vector<const char> name, Handle<String> source) { |
| 1191 HandleScope scope; | 1212 HandleScope scope; |
| 1192 Isolate* isolate = source->GetIsolate(); | 1213 Isolate* isolate = source->GetIsolate(); |
| 1193 #ifdef ENABLE_DEBUGGER_SUPPORT | 1214 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1194 isolate->debugger()->set_compiling_natives(true); | 1215 isolate->debugger()->set_compiling_natives(true); |
| 1195 #endif | 1216 #endif |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 INSTALL_NATIVE(JSFunction, "Instantiate", instantiate_fun); | 1303 INSTALL_NATIVE(JSFunction, "Instantiate", instantiate_fun); |
| 1283 INSTALL_NATIVE(JSFunction, "ConfigureTemplateInstance", | 1304 INSTALL_NATIVE(JSFunction, "ConfigureTemplateInstance", |
| 1284 configure_instance_fun); | 1305 configure_instance_fun); |
| 1285 INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun); | 1306 INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun); |
| 1286 INSTALL_NATIVE(JSObject, "functionCache", function_cache); | 1307 INSTALL_NATIVE(JSObject, "functionCache", function_cache); |
| 1287 } | 1308 } |
| 1288 | 1309 |
| 1289 void Genesis::InstallExperimentalNativeFunctions() { | 1310 void Genesis::InstallExperimentalNativeFunctions() { |
| 1290 if (FLAG_harmony_proxies) { | 1311 if (FLAG_harmony_proxies) { |
| 1291 INSTALL_NATIVE(JSFunction, "DerivedGetTrap", derived_get_trap); | 1312 INSTALL_NATIVE(JSFunction, "DerivedGetTrap", derived_get_trap); |
| 1313 INSTALL_NATIVE(JSFunction, "DerivedSetTrap", derived_set_trap); |
| 1292 } | 1314 } |
| 1293 } | 1315 } |
| 1294 | 1316 |
| 1295 #undef INSTALL_NATIVE | 1317 #undef INSTALL_NATIVE |
| 1296 | 1318 |
| 1297 | 1319 |
| 1298 bool Genesis::InstallNatives() { | 1320 bool Genesis::InstallNatives() { |
| 1299 HandleScope scope; | 1321 HandleScope scope; |
| 1300 | 1322 |
| 1301 // Create a function for the builtins object. Allocate space for the | 1323 // Create a function for the builtins object. Allocate space for the |
| (...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2175 return from + sizeof(NestingCounterType); | 2197 return from + sizeof(NestingCounterType); |
| 2176 } | 2198 } |
| 2177 | 2199 |
| 2178 | 2200 |
| 2179 // Called when the top-level V8 mutex is destroyed. | 2201 // Called when the top-level V8 mutex is destroyed. |
| 2180 void Bootstrapper::FreeThreadResources() { | 2202 void Bootstrapper::FreeThreadResources() { |
| 2181 ASSERT(!IsActive()); | 2203 ASSERT(!IsActive()); |
| 2182 } | 2204 } |
| 2183 | 2205 |
| 2184 } } // namespace v8::internal | 2206 } } // namespace v8::internal |
| OLD | NEW |