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

Side by Side Diff: src/bootstrapper.cc

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