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

Side by Side Diff: src/bootstrapper.cc

Issue 1123353008: Revert of Use function wrapper argument to expose internal arrays to native scripts. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
« no previous file with comments | « src/array.js ('k') | src/contexts.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/bootstrapper.h" 5 #include "src/bootstrapper.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/base/utils/random-number-generator.h" 9 #include "src/base/utils/random-number-generator.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 210
211 #define DECLARE_FEATURE_INITIALIZATION(id, descr) \ 211 #define DECLARE_FEATURE_INITIALIZATION(id, descr) \
212 void InstallNativeFunctions_##id(); \ 212 void InstallNativeFunctions_##id(); \
213 void InitializeGlobal_##id(); 213 void InitializeGlobal_##id();
214 214
215 HARMONY_INPROGRESS(DECLARE_FEATURE_INITIALIZATION) 215 HARMONY_INPROGRESS(DECLARE_FEATURE_INITIALIZATION)
216 HARMONY_STAGED(DECLARE_FEATURE_INITIALIZATION) 216 HARMONY_STAGED(DECLARE_FEATURE_INITIALIZATION)
217 HARMONY_SHIPPING(DECLARE_FEATURE_INITIALIZATION) 217 HARMONY_SHIPPING(DECLARE_FEATURE_INITIALIZATION)
218 #undef DECLARE_FEATURE_INITIALIZATION 218 #undef DECLARE_FEATURE_INITIALIZATION
219 219
220 Handle<JSFunction> InstallInternalArray(Handle<JSObject> target, 220 Handle<JSFunction> InstallInternalArray(Handle<JSBuiltinsObject> builtins,
221 const char* name, 221 const char* name,
222 ElementsKind elements_kind); 222 ElementsKind elements_kind);
223 bool InstallNatives(); 223 bool InstallNatives();
224 224
225 void InstallTypedArray( 225 void InstallTypedArray(
226 const char* name, 226 const char* name,
227 ElementsKind elements_kind, 227 ElementsKind elements_kind,
228 Handle<JSFunction>* fun, 228 Handle<JSFunction>* fun,
229 Handle<Map>* external_map); 229 Handle<Map>* external_map);
230 bool InstallExperimentalNatives(); 230 bool InstallExperimentalNatives();
231 bool InstallExtraNatives(); 231 bool InstallExtraNatives();
232 void InstallBuiltinFunctionIds(); 232 void InstallBuiltinFunctionIds();
233 void InstallJSFunctionResultCaches(); 233 void InstallJSFunctionResultCaches();
234 void InitializeNormalizedMapCaches(); 234 void InitializeNormalizedMapCaches();
235 235
236 void RemoveExportObjects();
237
238 enum ExtensionTraversalState { 236 enum ExtensionTraversalState {
239 UNVISITED, VISITED, INSTALLED 237 UNVISITED, VISITED, INSTALLED
240 }; 238 };
241 239
242 class ExtensionStates { 240 class ExtensionStates {
243 public: 241 public:
244 ExtensionStates(); 242 ExtensionStates();
245 ExtensionTraversalState get_state(RegisteredExtension* extension); 243 ExtensionTraversalState get_state(RegisteredExtension* extension);
246 void set_state(RegisteredExtension* extension, 244 void set_state(RegisteredExtension* extension,
247 ExtensionTraversalState state); 245 ExtensionTraversalState state);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 Handle<Map> CreateStrictFunctionMap(FunctionMode function_mode, 300 Handle<Map> CreateStrictFunctionMap(FunctionMode function_mode,
303 Handle<JSFunction> empty_function); 301 Handle<JSFunction> empty_function);
304 Handle<Map> CreateStrongFunctionMap(Handle<JSFunction> empty_function, 302 Handle<Map> CreateStrongFunctionMap(Handle<JSFunction> empty_function,
305 bool is_constructor); 303 bool is_constructor);
306 304
307 305
308 void SetStrictFunctionInstanceDescriptor(Handle<Map> map, 306 void SetStrictFunctionInstanceDescriptor(Handle<Map> map,
309 FunctionMode function_mode); 307 FunctionMode function_mode);
310 void SetStrongFunctionInstanceDescriptor(Handle<Map> map); 308 void SetStrongFunctionInstanceDescriptor(Handle<Map> map);
311 309
312 static bool CompileBuiltin(Isolate* isolate, int index, 310 static bool CompileBuiltin(Isolate* isolate, int index);
313 Handle<JSObject> shared);
314 static bool CompileExperimentalBuiltin(Isolate* isolate, int index); 311 static bool CompileExperimentalBuiltin(Isolate* isolate, int index);
315 static bool CompileExtraBuiltin(Isolate* isolate, int index); 312 static bool CompileExtraBuiltin(Isolate* isolate, int index);
316 static bool CompileNative(Isolate* isolate, Vector<const char> name, 313 static bool CompileNative(Isolate* isolate,
317 Handle<String> source, int argc, 314 Vector<const char> name,
318 Handle<Object> argv[]); 315 Handle<String> source);
319 316 static bool CompileScriptCached(Isolate* isolate,
320 static bool CompileExtension(Isolate* isolate, v8::Extension* extension); 317 Vector<const char> name,
318 Handle<String> source,
319 SourceCodeCache* cache,
320 v8::Extension* extension,
321 Handle<Context> top_context,
322 bool use_runtime_context);
321 323
322 Isolate* isolate_; 324 Isolate* isolate_;
323 Handle<Context> result_; 325 Handle<Context> result_;
324 Handle<Context> native_context_; 326 Handle<Context> native_context_;
325 327
326 // Function maps. Function maps are created initially with a read only 328 // Function maps. Function maps are created initially with a read only
327 // prototype for the processing of JS builtins. Later the function maps are 329 // prototype for the processing of JS builtins. Later the function maps are
328 // replaced in order to make prototype writable. These are the final, writable 330 // replaced in order to make prototype writable. These are the final, writable
329 // prototype, maps. 331 // prototype, maps.
330 Handle<Map> sloppy_function_map_writable_prototype_; 332 Handle<Map> sloppy_function_map_writable_prototype_;
(...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 void Genesis::InitializeExperimentalGlobal() { 1434 void Genesis::InitializeExperimentalGlobal() {
1433 #define FEATURE_INITIALIZE_GLOBAL(id, descr) InitializeGlobal_##id(); 1435 #define FEATURE_INITIALIZE_GLOBAL(id, descr) InitializeGlobal_##id();
1434 1436
1435 HARMONY_INPROGRESS(FEATURE_INITIALIZE_GLOBAL) 1437 HARMONY_INPROGRESS(FEATURE_INITIALIZE_GLOBAL)
1436 HARMONY_STAGED(FEATURE_INITIALIZE_GLOBAL) 1438 HARMONY_STAGED(FEATURE_INITIALIZE_GLOBAL)
1437 HARMONY_SHIPPING(FEATURE_INITIALIZE_GLOBAL) 1439 HARMONY_SHIPPING(FEATURE_INITIALIZE_GLOBAL)
1438 #undef FEATURE_INITIALIZE_GLOBAL 1440 #undef FEATURE_INITIALIZE_GLOBAL
1439 } 1441 }
1440 1442
1441 1443
1442 bool Genesis::CompileBuiltin(Isolate* isolate, int index, 1444 bool Genesis::CompileBuiltin(Isolate* isolate, int index) {
1443 Handle<JSObject> shared) {
1444 Vector<const char> name = Natives::GetScriptName(index); 1445 Vector<const char> name = Natives::GetScriptName(index);
1445 Handle<String> source_code = 1446 Handle<String> source_code =
1446 isolate->bootstrapper()->SourceLookup<Natives>(index); 1447 isolate->bootstrapper()->SourceLookup<Natives>(index);
1447 Handle<Object> global = isolate->global_object(); 1448 return CompileNative(isolate, name, source_code);
1448 Handle<Object> exports = isolate->builtin_exports_object();
1449 Handle<Object> args[] = {global, shared, exports};
1450 return CompileNative(isolate, name, source_code, arraysize(args), args);
1451 } 1449 }
1452 1450
1453 1451
1454 bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) { 1452 bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) {
1455 HandleScope scope(isolate);
1456 Vector<const char> name = ExperimentalNatives::GetScriptName(index); 1453 Vector<const char> name = ExperimentalNatives::GetScriptName(index);
1457 Handle<String> source_code = 1454 Handle<String> source_code =
1458 isolate->bootstrapper()->SourceLookup<ExperimentalNatives>(index); 1455 isolate->bootstrapper()->SourceLookup<ExperimentalNatives>(index);
1459 Handle<Object> global = isolate->global_object(); 1456 return CompileNative(isolate, name, source_code);
1460 Handle<Object> exports = isolate->builtin_exports_object();
1461 Handle<Object> args[] = {global, exports};
1462 return CompileNative(isolate, name, source_code, arraysize(args), args);
1463 } 1457 }
1464 1458
1465 1459
1466 bool Genesis::CompileExtraBuiltin(Isolate* isolate, int index) { 1460 bool Genesis::CompileExtraBuiltin(Isolate* isolate, int index) {
1467 HandleScope scope(isolate);
1468 Vector<const char> name = ExtraNatives::GetScriptName(index); 1461 Vector<const char> name = ExtraNatives::GetScriptName(index);
1469 Handle<String> source_code = 1462 Handle<String> source_code =
1470 isolate->bootstrapper()->SourceLookup<ExtraNatives>(index); 1463 isolate->bootstrapper()->SourceLookup<ExtraNatives>(index);
1471 Handle<Object> global = isolate->global_object(); 1464 return CompileNative(isolate, name, source_code);
1472 Handle<Object> exports = isolate->builtin_exports_object();
1473 Handle<Object> args[] = {global, exports};
1474 return CompileNative(isolate, name, source_code, arraysize(args), args);
1475 } 1465 }
1476 1466
1477 1467
1478 bool Genesis::CompileNative(Isolate* isolate, Vector<const char> name, 1468 bool Genesis::CompileNative(Isolate* isolate,
1479 Handle<String> source, int argc, 1469 Vector<const char> name,
1480 Handle<Object> argv[]) { 1470 Handle<String> source) {
1471 HandleScope scope(isolate);
1481 SuppressDebug compiling_natives(isolate->debug()); 1472 SuppressDebug compiling_natives(isolate->debug());
1482 // During genesis, the boilerplate for stack overflow won't work until the 1473 // During genesis, the boilerplate for stack overflow won't work until the
1483 // environment has been at least partially initialized. Add a stack check 1474 // environment has been at least partially initialized. Add a stack check
1484 // before entering JS code to catch overflow early. 1475 // before entering JS code to catch overflow early.
1485 StackLimitCheck check(isolate); 1476 StackLimitCheck check(isolate);
1486 if (check.HasOverflowed()) return false; 1477 if (check.HasOverflowed()) return false;
1487 1478
1488 Handle<Context> context(isolate->context()); 1479 bool result = CompileScriptCached(isolate,
1489 1480 name,
1490 Handle<String> script_name = 1481 source,
1491 isolate->factory()->NewStringFromUtf8(name).ToHandleChecked(); 1482 NULL,
1492 Handle<SharedFunctionInfo> function_info = Compiler::CompileScript( 1483 NULL,
1493 source, script_name, 0, 0, false, false, Handle<Object>(), context, NULL, 1484 Handle<Context>(isolate->context()),
1494 NULL, ScriptCompiler::kNoCompileOptions, NATIVES_CODE, false); 1485 true);
1495 1486 DCHECK(isolate->has_pending_exception() != result);
1496 DCHECK(context->IsNativeContext()); 1487 if (!result) isolate->clear_pending_exception();
1497 1488 return result;
1498 Handle<Context> runtime_context(context->runtime_context());
1499 Handle<JSBuiltinsObject> receiver(context->builtins());
1500 Handle<JSFunction> fun =
1501 isolate->factory()->NewFunctionFromSharedFunctionInfo(function_info,
1502 runtime_context);
1503
1504 // For non-extension scripts, run script to get the function wrapper.
1505 Handle<Object> wrapper;
1506 if (!Execution::Call(isolate, fun, receiver, 0, NULL).ToHandle(&wrapper)) {
1507 return false;
1508 }
1509 // Then run the function wrapper.
1510 return !Execution::Call(isolate, Handle<JSFunction>::cast(wrapper), receiver,
1511 argc, argv).is_null();
1512 } 1489 }
1513 1490
1514 1491
1515 bool Genesis::CompileExtension(Isolate* isolate, v8::Extension* extension) { 1492 bool Genesis::CompileScriptCached(Isolate* isolate,
1493 Vector<const char> name,
1494 Handle<String> source,
1495 SourceCodeCache* cache,
1496 v8::Extension* extension,
1497 Handle<Context> top_context,
1498 bool use_runtime_context) {
1516 Factory* factory = isolate->factory(); 1499 Factory* factory = isolate->factory();
1517 HandleScope scope(isolate); 1500 HandleScope scope(isolate);
1518 Handle<SharedFunctionInfo> function_info; 1501 Handle<SharedFunctionInfo> function_info;
1519 1502
1520 Handle<String> source =
1521 isolate->factory()
1522 ->NewExternalStringFromOneByte(extension->source())
1523 .ToHandleChecked();
1524 DCHECK(source->IsOneByteRepresentation());
1525
1526 // If we can't find the function in the cache, we compile a new 1503 // If we can't find the function in the cache, we compile a new
1527 // function and insert it into the cache. 1504 // function and insert it into the cache.
1528 Vector<const char> name = CStrVector(extension->name()); 1505 if (cache == NULL || !cache->Lookup(name, &function_info)) {
1529 SourceCodeCache* cache = isolate->bootstrapper()->extensions_cache(); 1506 DCHECK(source->IsOneByteRepresentation());
1530 Handle<Context> context(isolate->context());
1531 DCHECK(context->IsNativeContext());
1532
1533 if (!cache->Lookup(name, &function_info)) {
1534 Handle<String> script_name = 1507 Handle<String> script_name =
1535 factory->NewStringFromUtf8(name).ToHandleChecked(); 1508 factory->NewStringFromUtf8(name).ToHandleChecked();
1536 function_info = Compiler::CompileScript( 1509 function_info = Compiler::CompileScript(
1537 source, script_name, 0, 0, false, false, Handle<Object>(), context, 1510 source, script_name, 0, 0, false, false, Handle<Object>(), top_context,
1538 extension, NULL, ScriptCompiler::kNoCompileOptions, NOT_NATIVES_CODE, 1511 extension, NULL, ScriptCompiler::kNoCompileOptions,
1539 false); 1512 use_runtime_context ? NATIVES_CODE : NOT_NATIVES_CODE, false);
1540 if (function_info.is_null()) return false; 1513 if (function_info.is_null()) return false;
1541 cache->Add(name, function_info); 1514 if (cache != NULL) cache->Add(name, function_info);
1542 } 1515 }
1543 1516
1544 // Set up the function context. Conceptually, we should clone the 1517 // Set up the function context. Conceptually, we should clone the
1545 // function before overwriting the context but since we're in a 1518 // function before overwriting the context but since we're in a
1546 // single-threaded environment it is not strictly necessary. 1519 // single-threaded environment it is not strictly necessary.
1520 DCHECK(top_context->IsNativeContext());
1521 Handle<Context> context =
1522 Handle<Context>(use_runtime_context
1523 ? Handle<Context>(top_context->runtime_context())
1524 : top_context);
1547 Handle<JSFunction> fun = 1525 Handle<JSFunction> fun =
1548 factory->NewFunctionFromSharedFunctionInfo(function_info, context); 1526 factory->NewFunctionFromSharedFunctionInfo(function_info, context);
1549 1527
1550 // Call function using either the runtime object or the global 1528 // Call function using either the runtime object or the global
1551 // object as the receiver. Provide no parameters. 1529 // object as the receiver. Provide no parameters.
1552 Handle<Object> receiver = isolate->global_object(); 1530 Handle<Object> receiver =
1553 return !Execution::Call(isolate, fun, receiver, 0, NULL).is_null(); 1531 Handle<Object>(use_runtime_context
1532 ? top_context->builtins()
1533 : top_context->global_object(),
1534 isolate);
1535 MaybeHandle<Object> result;
1536 if (extension == NULL) {
1537 // For non-extension scripts, run script to get the function wrapper.
1538 Handle<Object> wrapper;
1539 if (!Execution::Call(isolate, fun, receiver, 0, NULL).ToHandle(&wrapper)) {
1540 return false;
1541 }
1542 // Then run the function wrapper.
1543 Handle<Object> global_obj(top_context->global_object(), isolate);
1544 Handle<Object> args[] = {global_obj};
1545 result = Execution::Call(isolate, Handle<JSFunction>::cast(wrapper),
1546 receiver, arraysize(args), args);
1547 } else {
1548 result = Execution::Call(isolate, fun, receiver, 0, NULL);
1549 }
1550 return !result.is_null();
1554 } 1551 }
1555 1552
1556 1553
1557 static Handle<JSObject> ResolveBuiltinIdHolder(Handle<Context> native_context, 1554 static Handle<JSObject> ResolveBuiltinIdHolder(Handle<Context> native_context,
1558 const char* holder_expr) { 1555 const char* holder_expr) {
1559 Isolate* isolate = native_context->GetIsolate(); 1556 Isolate* isolate = native_context->GetIsolate();
1560 Factory* factory = isolate->factory(); 1557 Factory* factory = isolate->factory();
1561 Handle<GlobalObject> global(native_context->global_object()); 1558 Handle<GlobalObject> global(native_context->global_object());
1562 const char* period_pos = strchr(holder_expr, '.'); 1559 const char* period_pos = strchr(holder_expr, '.');
1563 if (period_pos == NULL) { 1560 if (period_pos == NULL) {
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1814 Handle<JSObject> builtins(native_context()->builtins()); 1811 Handle<JSObject> builtins(native_context()->builtins());
1815 1812
1816 Handle<HeapObject> flag(FLAG_harmony_tostring ? heap()->true_value() 1813 Handle<HeapObject> flag(FLAG_harmony_tostring ? heap()->true_value()
1817 : heap()->false_value()); 1814 : heap()->false_value());
1818 Runtime::SetObjectProperty(isolate(), builtins, 1815 Runtime::SetObjectProperty(isolate(), builtins,
1819 factory()->harmony_tostring_string(), flag, 1816 factory()->harmony_tostring_string(), flag,
1820 STRICT).Assert(); 1817 STRICT).Assert();
1821 } 1818 }
1822 1819
1823 1820
1824 Handle<JSFunction> Genesis::InstallInternalArray(Handle<JSObject> target, 1821 Handle<JSFunction> Genesis::InstallInternalArray(
1825 const char* name, 1822 Handle<JSBuiltinsObject> builtins,
1826 ElementsKind elements_kind) { 1823 const char* name,
1824 ElementsKind elements_kind) {
1827 // --- I n t e r n a l A r r a y --- 1825 // --- I n t e r n a l A r r a y ---
1828 // An array constructor on the builtins object that works like 1826 // An array constructor on the builtins object that works like
1829 // the public Array constructor, except that its prototype 1827 // the public Array constructor, except that its prototype
1830 // doesn't inherit from Object.prototype. 1828 // doesn't inherit from Object.prototype.
1831 // To be used only for internal work by builtins. Instances 1829 // To be used only for internal work by builtins. Instances
1832 // must not be leaked to user code. 1830 // must not be leaked to user code.
1833 Handle<JSObject> prototype = 1831 Handle<JSObject> prototype =
1834 factory()->NewJSObject(isolate()->object_function(), TENURED); 1832 factory()->NewJSObject(isolate()->object_function(), TENURED);
1835 Handle<JSFunction> array_function = 1833 Handle<JSFunction> array_function = InstallFunction(
1836 InstallFunction(target, name, JS_ARRAY_TYPE, JSArray::kSize, prototype, 1834 builtins, name, JS_ARRAY_TYPE, JSArray::kSize,
1837 Builtins::kInternalArrayCode); 1835 prototype, Builtins::kInternalArrayCode);
1838 1836
1839 InternalArrayConstructorStub internal_array_constructor_stub(isolate()); 1837 InternalArrayConstructorStub internal_array_constructor_stub(isolate());
1840 Handle<Code> code = internal_array_constructor_stub.GetCode(); 1838 Handle<Code> code = internal_array_constructor_stub.GetCode();
1841 array_function->shared()->set_construct_stub(*code); 1839 array_function->shared()->set_construct_stub(*code);
1842 array_function->shared()->DontAdaptArguments(); 1840 array_function->shared()->DontAdaptArguments();
1843 1841
1844 Handle<Map> original_map(array_function->initial_map()); 1842 Handle<Map> original_map(array_function->initial_map());
1845 Handle<Map> initial_map = Map::Copy(original_map, "InternalArray"); 1843 Handle<Map> initial_map = Map::Copy(original_map, "InternalArray");
1846 initial_map->set_elements_kind(elements_kind); 1844 initial_map->set_elements_kind(elements_kind);
1847 JSFunction::SetInitialMap(array_function, initial_map, prototype); 1845 JSFunction::SetInitialMap(array_function, initial_map, prototype);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1905 Handle<JSFunction> bridge = factory()->NewFunction(factory()->empty_string()); 1903 Handle<JSFunction> bridge = factory()->NewFunction(factory()->empty_string());
1906 DCHECK(bridge->context() == *isolate()->native_context()); 1904 DCHECK(bridge->context() == *isolate()->native_context());
1907 1905
1908 // Allocate the builtins context. 1906 // Allocate the builtins context.
1909 Handle<Context> context = 1907 Handle<Context> context =
1910 factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge); 1908 factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge);
1911 context->set_global_object(*builtins); // override builtins global object 1909 context->set_global_object(*builtins); // override builtins global object
1912 1910
1913 native_context()->set_runtime_context(*context); 1911 native_context()->set_runtime_context(*context);
1914 1912
1915 // Set up shared object to set up cross references between native scripts.
1916 // "shared" is used for cross references between native scripts that are part
1917 // of the snapshot. "builtin_exports" is used for experimental natives.
1918 Handle<JSObject> shared =
1919 factory()->NewJSObject(isolate()->object_function());
1920 JSObject::NormalizeProperties(shared, CLEAR_INOBJECT_PROPERTIES, 16,
1921 "container to share between native scripts");
1922 Handle<JSObject> builtin_exports =
1923 factory()->NewJSObject(isolate()->object_function());
1924 JSObject::NormalizeProperties(builtin_exports, CLEAR_INOBJECT_PROPERTIES, 16,
1925 "container to export to experimental natives");
1926 native_context()->set_builtin_exports_object(*builtin_exports);
1927
1928 if (FLAG_expose_natives_as != nullptr) {
1929 Handle<String> shared_key = factory()->NewStringFromAsciiChecked("shared");
1930 Handle<String> builtin_exports_key =
1931 factory()->NewStringFromAsciiChecked("builtin_exports");
1932 JSObject::AddProperty(builtins, shared_key, shared, NONE);
1933 JSObject::AddProperty(builtins, builtin_exports_key, builtin_exports, NONE);
1934 }
1935
1936 { // -- S c r i p t 1913 { // -- S c r i p t
1937 // Builtin functions for Script. 1914 // Builtin functions for Script.
1938 Handle<JSFunction> script_fun = InstallFunction( 1915 Handle<JSFunction> script_fun = InstallFunction(
1939 builtins, "Script", JS_VALUE_TYPE, JSValue::kSize, 1916 builtins, "Script", JS_VALUE_TYPE, JSValue::kSize,
1940 isolate()->initial_object_prototype(), Builtins::kIllegal); 1917 isolate()->initial_object_prototype(), Builtins::kIllegal);
1941 Handle<JSObject> prototype = 1918 Handle<JSObject> prototype =
1942 factory()->NewJSObject(isolate()->object_function(), TENURED); 1919 factory()->NewJSObject(isolate()->object_function(), TENURED);
1943 Accessors::FunctionSetPrototype(script_fun, prototype).Assert(); 1920 Accessors::FunctionSetPrototype(script_fun, prototype).Assert();
1944 native_context()->set_script_function(*script_fun); 1921 native_context()->set_script_function(*script_fun);
1945 1922
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
2098 Accessors::FunctionSetPrototype(opaque_reference_fun, prototype).Assert(); 2075 Accessors::FunctionSetPrototype(opaque_reference_fun, prototype).Assert();
2099 native_context()->set_opaque_reference_function(*opaque_reference_fun); 2076 native_context()->set_opaque_reference_function(*opaque_reference_fun);
2100 } 2077 }
2101 2078
2102 // InternalArrays should not use Smi-Only array optimizations. There are too 2079 // InternalArrays should not use Smi-Only array optimizations. There are too
2103 // many places in the C++ runtime code (e.g. RegEx) that assume that 2080 // many places in the C++ runtime code (e.g. RegEx) that assume that
2104 // elements in InternalArrays can be set to non-Smi values without going 2081 // elements in InternalArrays can be set to non-Smi values without going
2105 // through a common bottleneck that would make the SMI_ONLY -> FAST_ELEMENT 2082 // through a common bottleneck that would make the SMI_ONLY -> FAST_ELEMENT
2106 // transition easy to trap. Moreover, they rarely are smi-only. 2083 // transition easy to trap. Moreover, they rarely are smi-only.
2107 { 2084 {
2108 HandleScope scope(isolate()); 2085 Handle<JSFunction> array_function =
2109 Handle<JSObject> builtin_exports = 2086 InstallInternalArray(builtins, "InternalArray", FAST_HOLEY_ELEMENTS);
2110 Handle<JSObject>::cast(isolate()->builtin_exports_object());
2111 Handle<JSFunction> array_function = InstallInternalArray(
2112 builtin_exports, "InternalArray", FAST_HOLEY_ELEMENTS);
2113 native_context()->set_internal_array_function(*array_function); 2087 native_context()->set_internal_array_function(*array_function);
2114 InstallInternalArray(builtin_exports, "InternalPackedArray", FAST_ELEMENTS); 2088 }
2089
2090 {
2091 InstallInternalArray(builtins, "InternalPackedArray", FAST_ELEMENTS);
2115 } 2092 }
2116 2093
2117 { // -- S e t I t e r a t o r 2094 { // -- S e t I t e r a t o r
2118 Handle<JSFunction> set_iterator_function = InstallFunction( 2095 Handle<JSFunction> set_iterator_function = InstallFunction(
2119 builtins, "SetIterator", JS_SET_ITERATOR_TYPE, JSSetIterator::kSize, 2096 builtins, "SetIterator", JS_SET_ITERATOR_TYPE, JSSetIterator::kSize,
2120 isolate()->initial_object_prototype(), Builtins::kIllegal); 2097 isolate()->initial_object_prototype(), Builtins::kIllegal);
2121 native_context()->set_set_iterator_map( 2098 native_context()->set_set_iterator_map(
2122 set_iterator_function->initial_map()); 2099 set_iterator_function->initial_map());
2123 } 2100 }
2124 2101
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2197 { 2174 {
2198 static const PropertyAttributes attributes = 2175 static const PropertyAttributes attributes =
2199 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); 2176 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE);
2200 #define INSTALL_PUBLIC_SYMBOL(name, varname, description) \ 2177 #define INSTALL_PUBLIC_SYMBOL(name, varname, description) \
2201 Handle<String> varname = factory()->NewStringFromStaticChars(#varname); \ 2178 Handle<String> varname = factory()->NewStringFromStaticChars(#varname); \
2202 JSObject::AddProperty(builtins, varname, factory()->name(), attributes); 2179 JSObject::AddProperty(builtins, varname, factory()->name(), attributes);
2203 PUBLIC_SYMBOL_LIST(INSTALL_PUBLIC_SYMBOL) 2180 PUBLIC_SYMBOL_LIST(INSTALL_PUBLIC_SYMBOL)
2204 #undef INSTALL_PUBLIC_SYMBOL 2181 #undef INSTALL_PUBLIC_SYMBOL
2205 } 2182 }
2206 2183
2207 // Install natives. Everything exported to experimental natives is also 2184 // Install natives.
2208 // shared to regular natives.
2209 TransferNamedProperties(builtin_exports, shared);
2210 int i = Natives::GetDebuggerCount(); 2185 int i = Natives::GetDebuggerCount();
2211 if (!CompileBuiltin(isolate(), i, shared)) return false; 2186 if (!CompileBuiltin(isolate(), i)) return false;
2212 if (!InstallJSBuiltins(builtins)) return false; 2187 if (!InstallJSBuiltins(builtins)) return false;
2213 2188
2214 for (++i; i < Natives::GetBuiltinsCount(); ++i) { 2189 for (++i; i < Natives::GetBuiltinsCount(); ++i) {
2215 if (!CompileBuiltin(isolate(), i, shared)) return false; 2190 if (!CompileBuiltin(isolate(), i)) return false;
2216 } 2191 }
2217 2192
2218 InstallNativeFunctions(); 2193 InstallNativeFunctions();
2219 2194
2220 auto function_cache = 2195 auto function_cache =
2221 ObjectHashTable::New(isolate(), ApiNatives::kInitialFunctionCacheSize); 2196 ObjectHashTable::New(isolate(), ApiNatives::kInitialFunctionCacheSize);
2222 native_context()->set_function_cache(*function_cache); 2197 native_context()->set_function_cache(*function_cache);
2223 2198
2224 // Store the map for the string prototype after the natives has been compiled 2199 // Store the map for the string prototype after the natives has been compiled
2225 // and the String function has been set up. 2200 // and the String function has been set up.
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
2409 bool Genesis::InstallExtraNatives() { 2384 bool Genesis::InstallExtraNatives() {
2410 for (int i = ExtraNatives::GetDebuggerCount(); 2385 for (int i = ExtraNatives::GetDebuggerCount();
2411 i < ExtraNatives::GetBuiltinsCount(); i++) { 2386 i < ExtraNatives::GetBuiltinsCount(); i++) {
2412 if (!CompileExtraBuiltin(isolate(), i)) return false; 2387 if (!CompileExtraBuiltin(isolate(), i)) return false;
2413 } 2388 }
2414 2389
2415 return true; 2390 return true;
2416 } 2391 }
2417 2392
2418 2393
2419 void Genesis::RemoveExportObjects() {
2420 native_context_->set_builtin_exports_object(Smi::FromInt(0));
2421 }
2422
2423
2424 static void InstallBuiltinFunctionId(Handle<JSObject> holder, 2394 static void InstallBuiltinFunctionId(Handle<JSObject> holder,
2425 const char* function_name, 2395 const char* function_name,
2426 BuiltinFunctionId id) { 2396 BuiltinFunctionId id) {
2427 Isolate* isolate = holder->GetIsolate(); 2397 Isolate* isolate = holder->GetIsolate();
2428 Handle<Object> function_object = 2398 Handle<Object> function_object =
2429 Object::GetProperty(isolate, holder, function_name).ToHandleChecked(); 2399 Object::GetProperty(isolate, holder, function_name).ToHandleChecked();
2430 Handle<JSFunction> function = Handle<JSFunction>::cast(function_object); 2400 Handle<JSFunction> function = Handle<JSFunction>::cast(function_object);
2431 function->shared()->set_function_data(Smi::FromInt(id)); 2401 function->shared()->set_function_data(Smi::FromInt(id));
2432 } 2402 }
2433 2403
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
2676 v8::Extension* extension = current->extension(); 2646 v8::Extension* extension = current->extension();
2677 // Install the extension's dependencies 2647 // Install the extension's dependencies
2678 for (int i = 0; i < extension->dependency_count(); i++) { 2648 for (int i = 0; i < extension->dependency_count(); i++) {
2679 if (!InstallExtension(isolate, 2649 if (!InstallExtension(isolate,
2680 extension->dependencies()[i], 2650 extension->dependencies()[i],
2681 extension_states)) { 2651 extension_states)) {
2682 return false; 2652 return false;
2683 } 2653 }
2684 } 2654 }
2685 // We do not expect this to throw an exception. Change this if it does. 2655 // We do not expect this to throw an exception. Change this if it does.
2686 bool result = CompileExtension(isolate, extension); 2656 Handle<String> source_code =
2657 isolate->factory()
2658 ->NewExternalStringFromOneByte(extension->source())
2659 .ToHandleChecked();
2660 bool result = CompileScriptCached(isolate,
2661 CStrVector(extension->name()),
2662 source_code,
2663 isolate->bootstrapper()->extensions_cache(),
2664 extension,
2665 Handle<Context>(isolate->context()),
2666 false);
2687 DCHECK(isolate->has_pending_exception() != result); 2667 DCHECK(isolate->has_pending_exception() != result);
2688 if (!result) { 2668 if (!result) {
2689 // We print out the name of the extension that fail to install. 2669 // We print out the name of the extension that fail to install.
2690 // When an error is thrown during bootstrapping we automatically print 2670 // When an error is thrown during bootstrapping we automatically print
2691 // the line number at which this happened to the console in the isolate 2671 // the line number at which this happened to the console in the isolate
2692 // error throwing functionality. 2672 // error throwing functionality.
2693 base::OS::PrintError("Error installing extension '%s'.\n", 2673 base::OS::PrintError("Error installing extension '%s'.\n",
2694 current->extension()->name()); 2674 current->extension()->name());
2695 isolate->clear_pending_exception(); 2675 isolate->clear_pending_exception();
2696 } 2676 }
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
2927 // The deserializer needs to hook up references to the global proxy. 2907 // The deserializer needs to hook up references to the global proxy.
2928 // Create an uninitialized global proxy now if we don't have one 2908 // Create an uninitialized global proxy now if we don't have one
2929 // and initialize it later in CreateNewGlobals. 2909 // and initialize it later in CreateNewGlobals.
2930 Handle<JSGlobalProxy> global_proxy; 2910 Handle<JSGlobalProxy> global_proxy;
2931 if (!maybe_global_proxy.ToHandle(&global_proxy)) { 2911 if (!maybe_global_proxy.ToHandle(&global_proxy)) {
2932 global_proxy = isolate->factory()->NewUninitializedJSGlobalProxy(); 2912 global_proxy = isolate->factory()->NewUninitializedJSGlobalProxy();
2933 } 2913 }
2934 2914
2935 // We can only de-serialize a context if the isolate was initialized from 2915 // We can only de-serialize a context if the isolate was initialized from
2936 // a snapshot. Otherwise we have to build the context from scratch. 2916 // a snapshot. Otherwise we have to build the context from scratch.
2937 // Also create a context from scratch to expose natives, if required by flag.
2938 Handle<FixedArray> outdated_contexts; 2917 Handle<FixedArray> outdated_contexts;
2939 if (FLAG_expose_natives_as != nullptr || 2918 if (!isolate->initialized_from_snapshot() ||
2940 !isolate->initialized_from_snapshot() ||
2941 !Snapshot::NewContextFromSnapshot(isolate, global_proxy, 2919 !Snapshot::NewContextFromSnapshot(isolate, global_proxy,
2942 &outdated_contexts) 2920 &outdated_contexts)
2943 .ToHandle(&native_context_)) { 2921 .ToHandle(&native_context_)) {
2944 native_context_ = Handle<Context>(); 2922 native_context_ = Handle<Context>();
2945 } 2923 }
2946 2924
2947 if (!native_context().is_null()) { 2925 if (!native_context().is_null()) {
2948 AddToWeakNativeContextList(*native_context()); 2926 AddToWeakNativeContextList(*native_context());
2949 isolate->set_context(*native_context()); 2927 isolate->set_context(*native_context());
2950 isolate->counters()->contexts_created_by_snapshot()->Increment(); 2928 isolate->counters()->contexts_created_by_snapshot()->Increment();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2986 isolate->counters()->contexts_created_from_scratch()->Increment(); 2964 isolate->counters()->contexts_created_from_scratch()->Increment();
2987 } 2965 }
2988 2966
2989 // Install experimental and extra natives. Do not include them into the 2967 // Install experimental and extra natives. Do not include them into the
2990 // snapshot as we should be able to turn them off at runtime. Re-installing 2968 // snapshot as we should be able to turn them off at runtime. Re-installing
2991 // them after they have already been deserialized would also fail. 2969 // them after they have already been deserialized would also fail.
2992 if (!isolate->serializer_enabled()) { 2970 if (!isolate->serializer_enabled()) {
2993 InitializeExperimentalGlobal(); 2971 InitializeExperimentalGlobal();
2994 if (!InstallExperimentalNatives()) return; 2972 if (!InstallExperimentalNatives()) return;
2995 if (!InstallExtraNatives()) return; 2973 if (!InstallExtraNatives()) return;
2996
2997 // Exports are no longer needed.
2998 RemoveExportObjects();
2999 } 2974 }
3000 2975
3001 // The serializer cannot serialize typed arrays. Reset those typed arrays 2976 // The serializer cannot serialize typed arrays. Reset those typed arrays
3002 // for each new context. 2977 // for each new context.
3003 InitializeBuiltinTypedArrays(); 2978 InitializeBuiltinTypedArrays();
3004 2979
3005 result_ = native_context(); 2980 result_ = native_context();
3006 } 2981 }
3007 2982
3008 2983
(...skipping 19 matching lines...) Expand all
3028 return from + sizeof(NestingCounterType); 3003 return from + sizeof(NestingCounterType);
3029 } 3004 }
3030 3005
3031 3006
3032 // Called when the top-level V8 mutex is destroyed. 3007 // Called when the top-level V8 mutex is destroyed.
3033 void Bootstrapper::FreeThreadResources() { 3008 void Bootstrapper::FreeThreadResources() {
3034 DCHECK(!IsActive()); 3009 DCHECK(!IsActive());
3035 } 3010 }
3036 3011
3037 } } // namespace v8::internal 3012 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/array.js ('k') | src/contexts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698