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

Side by Side Diff: src/bootstrapper.cc

Issue 1138173002: Reland "Use function wrapper argument to expose internal arrays to native scripts." (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: addressed nit 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();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 Handle<Map> CreateStrictFunctionMap(FunctionMode function_mode, 300 Handle<Map> CreateStrictFunctionMap(FunctionMode function_mode,
301 Handle<JSFunction> empty_function); 301 Handle<JSFunction> empty_function);
302 Handle<Map> CreateStrongFunctionMap(Handle<JSFunction> empty_function, 302 Handle<Map> CreateStrongFunctionMap(Handle<JSFunction> empty_function,
303 bool is_constructor); 303 bool is_constructor);
304 304
305 305
306 void SetStrictFunctionInstanceDescriptor(Handle<Map> map, 306 void SetStrictFunctionInstanceDescriptor(Handle<Map> map,
307 FunctionMode function_mode); 307 FunctionMode function_mode);
308 void SetStrongFunctionInstanceDescriptor(Handle<Map> map); 308 void SetStrongFunctionInstanceDescriptor(Handle<Map> map);
309 309
310 static bool CompileBuiltin(Isolate* isolate, int index); 310 static bool CompileBuiltin(Isolate* isolate, int index,
311 Handle<JSObject> shared);
311 static bool CompileExperimentalBuiltin(Isolate* isolate, int index); 312 static bool CompileExperimentalBuiltin(Isolate* isolate, int index);
312 static bool CompileExtraBuiltin(Isolate* isolate, int index); 313 static bool CompileExtraBuiltin(Isolate* isolate, int index);
313 static bool CompileNative(Isolate* isolate, 314 static bool CompileNative(Isolate* isolate, Vector<const char> name,
314 Vector<const char> name, 315 Handle<String> source, int argc,
315 Handle<String> source); 316 Handle<Object> argv[]);
316 static bool CompileScriptCached(Isolate* isolate, 317
317 Vector<const char> name, 318 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 319
324 Isolate* isolate_; 320 Isolate* isolate_;
325 Handle<Context> result_; 321 Handle<Context> result_;
326 Handle<Context> native_context_; 322 Handle<Context> native_context_;
327 323
328 // Function maps. Function maps are created initially with a read only 324 // Function maps. Function maps are created initially with a read only
329 // prototype for the processing of JS builtins. Later the function maps are 325 // 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 326 // replaced in order to make prototype writable. These are the final, writable
331 // prototype, maps. 327 // prototype, maps.
332 Handle<Map> sloppy_function_map_writable_prototype_; 328 Handle<Map> sloppy_function_map_writable_prototype_;
(...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 void Genesis::InitializeExperimentalGlobal() { 1430 void Genesis::InitializeExperimentalGlobal() {
1435 #define FEATURE_INITIALIZE_GLOBAL(id, descr) InitializeGlobal_##id(); 1431 #define FEATURE_INITIALIZE_GLOBAL(id, descr) InitializeGlobal_##id();
1436 1432
1437 HARMONY_INPROGRESS(FEATURE_INITIALIZE_GLOBAL) 1433 HARMONY_INPROGRESS(FEATURE_INITIALIZE_GLOBAL)
1438 HARMONY_STAGED(FEATURE_INITIALIZE_GLOBAL) 1434 HARMONY_STAGED(FEATURE_INITIALIZE_GLOBAL)
1439 HARMONY_SHIPPING(FEATURE_INITIALIZE_GLOBAL) 1435 HARMONY_SHIPPING(FEATURE_INITIALIZE_GLOBAL)
1440 #undef FEATURE_INITIALIZE_GLOBAL 1436 #undef FEATURE_INITIALIZE_GLOBAL
1441 } 1437 }
1442 1438
1443 1439
1444 bool Genesis::CompileBuiltin(Isolate* isolate, int index) { 1440 bool Genesis::CompileBuiltin(Isolate* isolate, int index,
1441 Handle<JSObject> shared) {
1445 Vector<const char> name = Natives::GetScriptName(index); 1442 Vector<const char> name = Natives::GetScriptName(index);
1446 Handle<String> source_code = 1443 Handle<String> source_code =
1447 isolate->bootstrapper()->SourceLookup<Natives>(index); 1444 isolate->bootstrapper()->SourceLookup<Natives>(index);
1448 return CompileNative(isolate, name, source_code); 1445 Handle<Object> global = isolate->global_object();
1446 Handle<Object> exports = isolate->builtin_exports_object();
1447 Handle<Object> args[] = {global, shared, exports};
1448 return CompileNative(isolate, name, source_code, arraysize(args), args);
1449 } 1449 }
1450 1450
1451 1451
1452 bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) { 1452 bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) {
1453 HandleScope scope(isolate);
1453 Vector<const char> name = ExperimentalNatives::GetScriptName(index); 1454 Vector<const char> name = ExperimentalNatives::GetScriptName(index);
1454 Handle<String> source_code = 1455 Handle<String> source_code =
1455 isolate->bootstrapper()->SourceLookup<ExperimentalNatives>(index); 1456 isolate->bootstrapper()->SourceLookup<ExperimentalNatives>(index);
1456 return CompileNative(isolate, name, source_code); 1457 Handle<Object> global = isolate->global_object();
1458 Handle<Object> exports = isolate->builtin_exports_object();
1459 Handle<Object> args[] = {global, exports};
1460 return CompileNative(isolate, name, source_code, arraysize(args), args);
1457 } 1461 }
1458 1462
1459 1463
1460 bool Genesis::CompileExtraBuiltin(Isolate* isolate, int index) { 1464 bool Genesis::CompileExtraBuiltin(Isolate* isolate, int index) {
1465 HandleScope scope(isolate);
1461 Vector<const char> name = ExtraNatives::GetScriptName(index); 1466 Vector<const char> name = ExtraNatives::GetScriptName(index);
1462 Handle<String> source_code = 1467 Handle<String> source_code =
1463 isolate->bootstrapper()->SourceLookup<ExtraNatives>(index); 1468 isolate->bootstrapper()->SourceLookup<ExtraNatives>(index);
1464 return CompileNative(isolate, name, source_code); 1469 Handle<Object> global = isolate->global_object();
1470 Handle<Object> exports = isolate->builtin_exports_object();
1471 Handle<Object> args[] = {global, exports};
1472 return CompileNative(isolate, name, source_code, arraysize(args), args);
1465 } 1473 }
1466 1474
1467 1475
1468 bool Genesis::CompileNative(Isolate* isolate, 1476 bool Genesis::CompileNative(Isolate* isolate, Vector<const char> name,
1469 Vector<const char> name, 1477 Handle<String> source, int argc,
1470 Handle<String> source) { 1478 Handle<Object> argv[]) {
1471 HandleScope scope(isolate);
1472 SuppressDebug compiling_natives(isolate->debug()); 1479 SuppressDebug compiling_natives(isolate->debug());
1473 // During genesis, the boilerplate for stack overflow won't work until the 1480 // During genesis, the boilerplate for stack overflow won't work until the
1474 // environment has been at least partially initialized. Add a stack check 1481 // environment has been at least partially initialized. Add a stack check
1475 // before entering JS code to catch overflow early. 1482 // before entering JS code to catch overflow early.
1476 StackLimitCheck check(isolate); 1483 StackLimitCheck check(isolate);
1477 if (check.HasOverflowed()) return false; 1484 if (check.HasOverflowed()) return false;
1478 1485
1479 bool result = CompileScriptCached(isolate, 1486 Handle<Context> context(isolate->context());
1480 name, 1487
1481 source, 1488 Handle<String> script_name =
1482 NULL, 1489 isolate->factory()->NewStringFromUtf8(name).ToHandleChecked();
1483 NULL, 1490 Handle<SharedFunctionInfo> function_info = Compiler::CompileScript(
1484 Handle<Context>(isolate->context()), 1491 source, script_name, 0, 0, false, false, Handle<Object>(), context, NULL,
1485 true); 1492 NULL, ScriptCompiler::kNoCompileOptions, NATIVES_CODE, false);
1486 DCHECK(isolate->has_pending_exception() != result); 1493
1487 if (!result) isolate->clear_pending_exception(); 1494 DCHECK(context->IsNativeContext());
1488 return result; 1495
1496 Handle<Context> runtime_context(context->runtime_context());
1497 Handle<JSBuiltinsObject> receiver(context->builtins());
1498 Handle<JSFunction> fun =
1499 isolate->factory()->NewFunctionFromSharedFunctionInfo(function_info,
1500 runtime_context);
1501
1502 // For non-extension scripts, run script to get the function wrapper.
1503 Handle<Object> wrapper;
1504 if (!Execution::Call(isolate, fun, receiver, 0, NULL).ToHandle(&wrapper)) {
1505 return false;
1506 }
1507 // Then run the function wrapper.
1508 return !Execution::Call(isolate, Handle<JSFunction>::cast(wrapper), receiver,
1509 argc, argv).is_null();
1489 } 1510 }
1490 1511
1491 1512
1492 bool Genesis::CompileScriptCached(Isolate* isolate, 1513 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(); 1514 Factory* factory = isolate->factory();
1500 HandleScope scope(isolate); 1515 HandleScope scope(isolate);
1501 Handle<SharedFunctionInfo> function_info; 1516 Handle<SharedFunctionInfo> function_info;
1502 1517
1518 Handle<String> source =
1519 isolate->factory()
1520 ->NewExternalStringFromOneByte(extension->source())
1521 .ToHandleChecked();
1522 DCHECK(source->IsOneByteRepresentation());
1523
1503 // If we can't find the function in the cache, we compile a new 1524 // If we can't find the function in the cache, we compile a new
1504 // function and insert it into the cache. 1525 // function and insert it into the cache.
1505 if (cache == NULL || !cache->Lookup(name, &function_info)) { 1526 Vector<const char> name = CStrVector(extension->name());
1506 DCHECK(source->IsOneByteRepresentation()); 1527 SourceCodeCache* cache = isolate->bootstrapper()->extensions_cache();
1528 Handle<Context> context(isolate->context());
1529 DCHECK(context->IsNativeContext());
1530
1531 if (!cache->Lookup(name, &function_info)) {
1507 Handle<String> script_name = 1532 Handle<String> script_name =
1508 factory->NewStringFromUtf8(name).ToHandleChecked(); 1533 factory->NewStringFromUtf8(name).ToHandleChecked();
1509 function_info = Compiler::CompileScript( 1534 function_info = Compiler::CompileScript(
1510 source, script_name, 0, 0, false, false, Handle<Object>(), top_context, 1535 source, script_name, 0, 0, false, false, Handle<Object>(), context,
1511 extension, NULL, ScriptCompiler::kNoCompileOptions, 1536 extension, NULL, ScriptCompiler::kNoCompileOptions, NOT_NATIVES_CODE,
1512 use_runtime_context ? NATIVES_CODE : NOT_NATIVES_CODE, false); 1537 false);
1513 if (function_info.is_null()) return false; 1538 if (function_info.is_null()) return false;
1514 if (cache != NULL) cache->Add(name, function_info); 1539 cache->Add(name, function_info);
1515 } 1540 }
1516 1541
1517 // Set up the function context. Conceptually, we should clone the 1542 // Set up the function context. Conceptually, we should clone the
1518 // function before overwriting the context but since we're in a 1543 // function before overwriting the context but since we're in a
1519 // single-threaded environment it is not strictly necessary. 1544 // 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 = 1545 Handle<JSFunction> fun =
1526 factory->NewFunctionFromSharedFunctionInfo(function_info, context); 1546 factory->NewFunctionFromSharedFunctionInfo(function_info, context);
1527 1547
1528 // Call function using either the runtime object or the global 1548 // Call function using either the runtime object or the global
1529 // object as the receiver. Provide no parameters. 1549 // object as the receiver. Provide no parameters.
1530 Handle<Object> receiver = 1550 Handle<Object> receiver = isolate->global_object();
1531 Handle<Object>(use_runtime_context 1551 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 } 1552 }
1552 1553
1553 1554
1554 static Handle<JSObject> ResolveBuiltinIdHolder(Handle<Context> native_context, 1555 static Handle<JSObject> ResolveBuiltinIdHolder(Handle<Context> native_context,
1555 const char* holder_expr) { 1556 const char* holder_expr) {
1556 Isolate* isolate = native_context->GetIsolate(); 1557 Isolate* isolate = native_context->GetIsolate();
1557 Factory* factory = isolate->factory(); 1558 Factory* factory = isolate->factory();
1558 Handle<GlobalObject> global(native_context->global_object()); 1559 Handle<GlobalObject> global(native_context->global_object());
1559 const char* period_pos = strchr(holder_expr, '.'); 1560 const char* period_pos = strchr(holder_expr, '.');
1560 if (period_pos == NULL) { 1561 if (period_pos == NULL) {
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 Handle<JSObject> builtins(native_context()->builtins()); 1812 Handle<JSObject> builtins(native_context()->builtins());
1812 1813
1813 Handle<HeapObject> flag(FLAG_harmony_tostring ? heap()->true_value() 1814 Handle<HeapObject> flag(FLAG_harmony_tostring ? heap()->true_value()
1814 : heap()->false_value()); 1815 : heap()->false_value());
1815 Runtime::SetObjectProperty(isolate(), builtins, 1816 Runtime::SetObjectProperty(isolate(), builtins,
1816 factory()->harmony_tostring_string(), flag, 1817 factory()->harmony_tostring_string(), flag,
1817 STRICT).Assert(); 1818 STRICT).Assert();
1818 } 1819 }
1819 1820
1820 1821
1821 Handle<JSFunction> Genesis::InstallInternalArray( 1822 Handle<JSFunction> Genesis::InstallInternalArray(Handle<JSObject> target,
1822 Handle<JSBuiltinsObject> builtins, 1823 const char* name,
1823 const char* name, 1824 ElementsKind elements_kind) {
1824 ElementsKind elements_kind) {
1825 // --- 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 ---
1826 // An array constructor on the builtins object that works like 1826 // An array constructor on the builtins object that works like
1827 // the public Array constructor, except that its prototype 1827 // the public Array constructor, except that its prototype
1828 // doesn't inherit from Object.prototype. 1828 // doesn't inherit from Object.prototype.
1829 // To be used only for internal work by builtins. Instances 1829 // To be used only for internal work by builtins. Instances
1830 // must not be leaked to user code. 1830 // must not be leaked to user code.
1831 Handle<JSObject> prototype = 1831 Handle<JSObject> prototype =
1832 factory()->NewJSObject(isolate()->object_function(), TENURED); 1832 factory()->NewJSObject(isolate()->object_function(), TENURED);
1833 Handle<JSFunction> array_function = InstallFunction( 1833 Handle<JSFunction> array_function =
1834 builtins, name, JS_ARRAY_TYPE, JSArray::kSize, 1834 InstallFunction(target, name, JS_ARRAY_TYPE, JSArray::kSize, prototype,
1835 prototype, Builtins::kInternalArrayCode); 1835 Builtins::kInternalArrayCode);
1836 1836
1837 InternalArrayConstructorStub internal_array_constructor_stub(isolate()); 1837 InternalArrayConstructorStub internal_array_constructor_stub(isolate());
1838 Handle<Code> code = internal_array_constructor_stub.GetCode(); 1838 Handle<Code> code = internal_array_constructor_stub.GetCode();
1839 array_function->shared()->set_construct_stub(*code); 1839 array_function->shared()->set_construct_stub(*code);
1840 array_function->shared()->DontAdaptArguments(); 1840 array_function->shared()->DontAdaptArguments();
1841 1841
1842 Handle<Map> original_map(array_function->initial_map()); 1842 Handle<Map> original_map(array_function->initial_map());
1843 Handle<Map> initial_map = Map::Copy(original_map, "InternalArray"); 1843 Handle<Map> initial_map = Map::Copy(original_map, "InternalArray");
1844 initial_map->set_elements_kind(elements_kind); 1844 initial_map->set_elements_kind(elements_kind);
1845 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
1903 Handle<JSFunction> bridge = factory()->NewFunction(factory()->empty_string()); 1903 Handle<JSFunction> bridge = factory()->NewFunction(factory()->empty_string());
1904 DCHECK(bridge->context() == *isolate()->native_context()); 1904 DCHECK(bridge->context() == *isolate()->native_context());
1905 1905
1906 // Allocate the builtins context. 1906 // Allocate the builtins context.
1907 Handle<Context> context = 1907 Handle<Context> context =
1908 factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge); 1908 factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge);
1909 context->set_global_object(*builtins); // override builtins global object 1909 context->set_global_object(*builtins); // override builtins global object
1910 1910
1911 native_context()->set_runtime_context(*context); 1911 native_context()->set_runtime_context(*context);
1912 1912
1913 // Set up shared object to set up cross references between native scripts.
1914 // "shared" is used for cross references between native scripts that are part
1915 // of the snapshot. "builtin_exports" is used for experimental natives.
1916 Handle<JSObject> shared =
1917 factory()->NewJSObject(isolate()->object_function());
1918 JSObject::NormalizeProperties(shared, CLEAR_INOBJECT_PROPERTIES, 16,
1919 "container to share between native scripts");
1920 Handle<JSObject> builtin_exports =
1921 factory()->NewJSObject(isolate()->object_function());
1922 JSObject::NormalizeProperties(builtin_exports, CLEAR_INOBJECT_PROPERTIES, 16,
1923 "container to export to experimental natives");
1924 native_context()->set_builtin_exports_object(*builtin_exports);
1925
1913 { // -- S c r i p t 1926 { // -- S c r i p t
1914 // Builtin functions for Script. 1927 // Builtin functions for Script.
1915 Handle<JSFunction> script_fun = InstallFunction( 1928 Handle<JSFunction> script_fun = InstallFunction(
1916 builtins, "Script", JS_VALUE_TYPE, JSValue::kSize, 1929 builtins, "Script", JS_VALUE_TYPE, JSValue::kSize,
1917 isolate()->initial_object_prototype(), Builtins::kIllegal); 1930 isolate()->initial_object_prototype(), Builtins::kIllegal);
1918 Handle<JSObject> prototype = 1931 Handle<JSObject> prototype =
1919 factory()->NewJSObject(isolate()->object_function(), TENURED); 1932 factory()->NewJSObject(isolate()->object_function(), TENURED);
1920 Accessors::FunctionSetPrototype(script_fun, prototype).Assert(); 1933 Accessors::FunctionSetPrototype(script_fun, prototype).Assert();
1921 native_context()->set_script_function(*script_fun); 1934 native_context()->set_script_function(*script_fun);
1922 1935
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
2075 Accessors::FunctionSetPrototype(opaque_reference_fun, prototype).Assert(); 2088 Accessors::FunctionSetPrototype(opaque_reference_fun, prototype).Assert();
2076 native_context()->set_opaque_reference_function(*opaque_reference_fun); 2089 native_context()->set_opaque_reference_function(*opaque_reference_fun);
2077 } 2090 }
2078 2091
2079 // InternalArrays should not use Smi-Only array optimizations. There are too 2092 // 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 2093 // 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 2094 // 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 2095 // through a common bottleneck that would make the SMI_ONLY -> FAST_ELEMENT
2083 // transition easy to trap. Moreover, they rarely are smi-only. 2096 // transition easy to trap. Moreover, they rarely are smi-only.
2084 { 2097 {
2085 Handle<JSFunction> array_function = 2098 HandleScope scope(isolate());
2086 InstallInternalArray(builtins, "InternalArray", FAST_HOLEY_ELEMENTS); 2099 Handle<JSObject> builtin_exports =
2100 Handle<JSObject>::cast(isolate()->builtin_exports_object());
2101 Handle<JSFunction> array_function = InstallInternalArray(
2102 builtin_exports, "InternalArray", FAST_HOLEY_ELEMENTS);
2087 native_context()->set_internal_array_function(*array_function); 2103 native_context()->set_internal_array_function(*array_function);
2088 } 2104 InstallInternalArray(builtin_exports, "InternalPackedArray", FAST_ELEMENTS);
2089
2090 {
2091 InstallInternalArray(builtins, "InternalPackedArray", FAST_ELEMENTS);
2092 } 2105 }
2093 2106
2094 { // -- S e t I t e r a t o r 2107 { // -- S e t I t e r a t o r
2095 Handle<JSFunction> set_iterator_function = InstallFunction( 2108 Handle<JSFunction> set_iterator_function = InstallFunction(
2096 builtins, "SetIterator", JS_SET_ITERATOR_TYPE, JSSetIterator::kSize, 2109 builtins, "SetIterator", JS_SET_ITERATOR_TYPE, JSSetIterator::kSize,
2097 isolate()->initial_object_prototype(), Builtins::kIllegal); 2110 isolate()->initial_object_prototype(), Builtins::kIllegal);
2098 native_context()->set_set_iterator_map( 2111 native_context()->set_set_iterator_map(
2099 set_iterator_function->initial_map()); 2112 set_iterator_function->initial_map());
2100 } 2113 }
2101 2114
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2174 { 2187 {
2175 static const PropertyAttributes attributes = 2188 static const PropertyAttributes attributes =
2176 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); 2189 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE);
2177 #define INSTALL_PUBLIC_SYMBOL(name, varname, description) \ 2190 #define INSTALL_PUBLIC_SYMBOL(name, varname, description) \
2178 Handle<String> varname = factory()->NewStringFromStaticChars(#varname); \ 2191 Handle<String> varname = factory()->NewStringFromStaticChars(#varname); \
2179 JSObject::AddProperty(builtins, varname, factory()->name(), attributes); 2192 JSObject::AddProperty(builtins, varname, factory()->name(), attributes);
2180 PUBLIC_SYMBOL_LIST(INSTALL_PUBLIC_SYMBOL) 2193 PUBLIC_SYMBOL_LIST(INSTALL_PUBLIC_SYMBOL)
2181 #undef INSTALL_PUBLIC_SYMBOL 2194 #undef INSTALL_PUBLIC_SYMBOL
2182 } 2195 }
2183 2196
2184 // Install natives. 2197 // Install natives. Everything exported to experimental natives is also
2198 // shared to regular natives.
2199 TransferNamedProperties(builtin_exports, shared);
2185 int i = Natives::GetDebuggerCount(); 2200 int i = Natives::GetDebuggerCount();
2186 if (!CompileBuiltin(isolate(), i)) return false; 2201 if (!CompileBuiltin(isolate(), i, shared)) return false;
2187 if (!InstallJSBuiltins(builtins)) return false; 2202 if (!InstallJSBuiltins(builtins)) return false;
2188 2203
2189 for (++i; i < Natives::GetBuiltinsCount(); ++i) { 2204 for (++i; i < Natives::GetBuiltinsCount(); ++i) {
2190 if (!CompileBuiltin(isolate(), i)) return false; 2205 if (!CompileBuiltin(isolate(), i, shared)) return false;
2191 } 2206 }
2192 2207
2193 InstallNativeFunctions(); 2208 InstallNativeFunctions();
2194 2209
2195 auto function_cache = 2210 auto function_cache =
2196 ObjectHashTable::New(isolate(), ApiNatives::kInitialFunctionCacheSize); 2211 ObjectHashTable::New(isolate(), ApiNatives::kInitialFunctionCacheSize);
2197 native_context()->set_function_cache(*function_cache); 2212 native_context()->set_function_cache(*function_cache);
2198 2213
2199 // Store the map for the string prototype after the natives has been compiled 2214 // Store the map for the string prototype after the natives has been compiled
2200 // and the String function has been set up. 2215 // and the String function has been set up.
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
2495 Handle<JSGlobalObject> global(JSGlobalObject::cast( 2510 Handle<JSGlobalObject> global(JSGlobalObject::cast(
2496 native_context->global_object())); 2511 native_context->global_object()));
2497 2512
2498 Handle<JSObject> Error = Handle<JSObject>::cast( 2513 Handle<JSObject> Error = Handle<JSObject>::cast(
2499 Object::GetProperty(isolate, global, "Error").ToHandleChecked()); 2514 Object::GetProperty(isolate, global, "Error").ToHandleChecked());
2500 Handle<String> name = 2515 Handle<String> name =
2501 factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("stackTraceLimit")); 2516 factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("stackTraceLimit"));
2502 Handle<Smi> stack_trace_limit(Smi::FromInt(FLAG_stack_trace_limit), isolate); 2517 Handle<Smi> stack_trace_limit(Smi::FromInt(FLAG_stack_trace_limit), isolate);
2503 JSObject::AddProperty(Error, name, stack_trace_limit, NONE); 2518 JSObject::AddProperty(Error, name, stack_trace_limit, NONE);
2504 2519
2520 Handle<Object> builtin_exports(native_context->builtin_exports_object(),
2521 isolate);
2522 native_context->set_builtin_exports_object(Smi::FromInt(0));
2523
2505 // Expose the natives in global if a name for it is specified. 2524 // Expose the natives in global if a name for it is specified.
2506 if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) { 2525 if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) {
2507 Handle<String> natives = 2526 Handle<String> natives_key =
2508 factory->InternalizeUtf8String(FLAG_expose_natives_as); 2527 factory->InternalizeUtf8String(FLAG_expose_natives_as);
2509 uint32_t dummy_index; 2528 uint32_t dummy_index;
2510 if (natives->AsArrayIndex(&dummy_index)) return true; 2529 if (natives_key->AsArrayIndex(&dummy_index)) return true;
2511 JSObject::AddProperty(global, natives, handle(global->builtins()), 2530 Handle<JSBuiltinsObject> natives(global->builtins());
2512 DONT_ENUM); 2531 JSObject::AddProperty(global, natives_key, natives, DONT_ENUM);
2532 Handle<String> builtin_exports_key =
2533 factory->NewStringFromAsciiChecked("builtin_exports");
2534 JSObject::AddProperty(natives, builtin_exports_key, builtin_exports, NONE);
2513 } 2535 }
2514 2536
2515 // Expose the stack trace symbol to native JS. 2537 // Expose the stack trace symbol to native JS.
2516 RETURN_ON_EXCEPTION_VALUE(isolate, 2538 RETURN_ON_EXCEPTION_VALUE(isolate,
2517 JSObject::SetOwnPropertyIgnoreAttributes( 2539 JSObject::SetOwnPropertyIgnoreAttributes(
2518 handle(native_context->builtins(), isolate), 2540 handle(native_context->builtins(), isolate),
2519 factory->InternalizeOneByteString( 2541 factory->InternalizeOneByteString(
2520 STATIC_CHAR_VECTOR("$stackTraceSymbol")), 2542 STATIC_CHAR_VECTOR("$stackTraceSymbol")),
2521 factory->stack_trace_symbol(), NONE), 2543 factory->stack_trace_symbol(), NONE),
2522 false); 2544 false);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
2646 v8::Extension* extension = current->extension(); 2668 v8::Extension* extension = current->extension();
2647 // Install the extension's dependencies 2669 // Install the extension's dependencies
2648 for (int i = 0; i < extension->dependency_count(); i++) { 2670 for (int i = 0; i < extension->dependency_count(); i++) {
2649 if (!InstallExtension(isolate, 2671 if (!InstallExtension(isolate,
2650 extension->dependencies()[i], 2672 extension->dependencies()[i],
2651 extension_states)) { 2673 extension_states)) {
2652 return false; 2674 return false;
2653 } 2675 }
2654 } 2676 }
2655 // We do not expect this to throw an exception. Change this if it does. 2677 // We do not expect this to throw an exception. Change this if it does.
2656 Handle<String> source_code = 2678 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); 2679 DCHECK(isolate->has_pending_exception() != result);
2668 if (!result) { 2680 if (!result) {
2669 // We print out the name of the extension that fail to install. 2681 // We print out the name of the extension that fail to install.
2670 // When an error is thrown during bootstrapping we automatically print 2682 // When an error is thrown during bootstrapping we automatically print
2671 // the line number at which this happened to the console in the isolate 2683 // the line number at which this happened to the console in the isolate
2672 // error throwing functionality. 2684 // error throwing functionality.
2673 base::OS::PrintError("Error installing extension '%s'.\n", 2685 base::OS::PrintError("Error installing extension '%s'.\n",
2674 current->extension()->name()); 2686 current->extension()->name());
2675 isolate->clear_pending_exception(); 2687 isolate->clear_pending_exception();
2676 } 2688 }
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
2907 // The deserializer needs to hook up references to the global proxy. 2919 // The deserializer needs to hook up references to the global proxy.
2908 // Create an uninitialized global proxy now if we don't have one 2920 // Create an uninitialized global proxy now if we don't have one
2909 // and initialize it later in CreateNewGlobals. 2921 // and initialize it later in CreateNewGlobals.
2910 Handle<JSGlobalProxy> global_proxy; 2922 Handle<JSGlobalProxy> global_proxy;
2911 if (!maybe_global_proxy.ToHandle(&global_proxy)) { 2923 if (!maybe_global_proxy.ToHandle(&global_proxy)) {
2912 global_proxy = isolate->factory()->NewUninitializedJSGlobalProxy(); 2924 global_proxy = isolate->factory()->NewUninitializedJSGlobalProxy();
2913 } 2925 }
2914 2926
2915 // We can only de-serialize a context if the isolate was initialized from 2927 // 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. 2928 // a snapshot. Otherwise we have to build the context from scratch.
2929 // Also create a context from scratch to expose natives, if required by flag.
2917 Handle<FixedArray> outdated_contexts; 2930 Handle<FixedArray> outdated_contexts;
2918 if (!isolate->initialized_from_snapshot() || 2931 if (!isolate->initialized_from_snapshot() ||
2919 !Snapshot::NewContextFromSnapshot(isolate, global_proxy, 2932 !Snapshot::NewContextFromSnapshot(isolate, global_proxy,
2920 &outdated_contexts) 2933 &outdated_contexts)
2921 .ToHandle(&native_context_)) { 2934 .ToHandle(&native_context_)) {
2922 native_context_ = Handle<Context>(); 2935 native_context_ = Handle<Context>();
2923 } 2936 }
2924 2937
2925 if (!native_context().is_null()) { 2938 if (!native_context().is_null()) {
2926 AddToWeakNativeContextList(*native_context()); 2939 AddToWeakNativeContextList(*native_context());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
3003 return from + sizeof(NestingCounterType); 3016 return from + sizeof(NestingCounterType);
3004 } 3017 }
3005 3018
3006 3019
3007 // Called when the top-level V8 mutex is destroyed. 3020 // Called when the top-level V8 mutex is destroyed.
3008 void Bootstrapper::FreeThreadResources() { 3021 void Bootstrapper::FreeThreadResources() {
3009 DCHECK(!IsActive()); 3022 DCHECK(!IsActive());
3010 } 3023 }
3011 3024
3012 } } // namespace v8::internal 3025 } } // 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