OLD | NEW |
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/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/extensions/externalize-string-extension.h" | 10 #include "src/extensions/externalize-string-extension.h" |
(...skipping 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1239 isolate->initial_object_prototype(), Builtins::kSymbolConstructor); | 1239 isolate->initial_object_prototype(), Builtins::kSymbolConstructor); |
1240 symbol_fun->shared()->set_construct_stub( | 1240 symbol_fun->shared()->set_construct_stub( |
1241 *isolate->builtins()->SymbolConstructor_ConstructStub()); | 1241 *isolate->builtins()->SymbolConstructor_ConstructStub()); |
1242 symbol_fun->shared()->set_length(1); | 1242 symbol_fun->shared()->set_length(1); |
1243 symbol_fun->shared()->DontAdaptArguments(); | 1243 symbol_fun->shared()->DontAdaptArguments(); |
1244 native_context()->set_symbol_function(*symbol_fun); | 1244 native_context()->set_symbol_function(*symbol_fun); |
1245 } | 1245 } |
1246 | 1246 |
1247 { // --- D a t e --- | 1247 { // --- D a t e --- |
1248 // Builtin functions for Date.prototype. | 1248 // Builtin functions for Date.prototype. |
1249 Handle<JSObject> prototype = | 1249 Handle<JSFunction> date_fun = InstallFunction( |
1250 factory->NewJSObject(isolate->object_function(), TENURED); | 1250 global, "Date", JS_DATE_TYPE, JSDate::kSize, |
1251 Handle<JSFunction> date_fun = | 1251 isolate->initial_object_prototype(), Builtins::kDateConstructor); |
1252 InstallFunction(global, "Date", JS_DATE_TYPE, JSDate::kSize, prototype, | |
1253 Builtins::kDateConstructor); | |
1254 InstallWithIntrinsicDefaultProto(isolate, date_fun, | 1252 InstallWithIntrinsicDefaultProto(isolate, date_fun, |
1255 Context::DATE_FUNCTION_INDEX); | 1253 Context::DATE_FUNCTION_INDEX); |
1256 date_fun->shared()->set_construct_stub( | 1254 date_fun->shared()->set_construct_stub( |
1257 *isolate->builtins()->DateConstructor_ConstructStub()); | 1255 *isolate->builtins()->DateConstructor_ConstructStub()); |
1258 date_fun->shared()->set_length(7); | 1256 date_fun->shared()->set_length(7); |
1259 date_fun->shared()->DontAdaptArguments(); | 1257 date_fun->shared()->DontAdaptArguments(); |
1260 | |
1261 // Install the Date.now, Date.parse and Date.UTC functions. | |
1262 SimpleInstallFunction(date_fun, "now", Builtins::kDateNow, 0, false); | |
1263 SimpleInstallFunction(date_fun, "parse", Builtins::kDateParse, 1, false); | |
1264 SimpleInstallFunction(date_fun, "UTC", Builtins::kDateUTC, 7, false); | |
1265 | |
1266 // Install the "constructor" property on the {prototype}. | |
1267 JSObject::AddProperty(prototype, factory->constructor_string(), date_fun, | |
1268 DONT_ENUM); | |
1269 | |
1270 // Install the Date.prototype methods. | |
1271 SimpleInstallFunction(prototype, "toString", | |
1272 Builtins::kDatePrototypeToString, 0, false); | |
1273 SimpleInstallFunction(prototype, "toDateString", | |
1274 Builtins::kDatePrototypeToDateString, 0, false); | |
1275 SimpleInstallFunction(prototype, "toTimeString", | |
1276 Builtins::kDatePrototypeToTimeString, 0, false); | |
1277 SimpleInstallFunction(prototype, "toGMTString", | |
1278 Builtins::kDatePrototypeToUTCString, 0, false); | |
1279 SimpleInstallFunction(prototype, "toISOString", | |
1280 Builtins::kDatePrototypeToISOString, 0, false); | |
1281 SimpleInstallFunction(prototype, "toUTCString", | |
1282 Builtins::kDatePrototypeToUTCString, 0, false); | |
1283 SimpleInstallFunction(prototype, "getDate", Builtins::kDatePrototypeGetDate, | |
1284 0, true); | |
1285 SimpleInstallFunction(prototype, "setDate", Builtins::kDatePrototypeSetDate, | |
1286 1, false); | |
1287 SimpleInstallFunction(prototype, "getDay", Builtins::kDatePrototypeGetDay, | |
1288 0, true); | |
1289 SimpleInstallFunction(prototype, "getFullYear", | |
1290 Builtins::kDatePrototypeGetFullYear, 0, true); | |
1291 SimpleInstallFunction(prototype, "setFullYear", | |
1292 Builtins::kDatePrototypeSetFullYear, 3, false); | |
1293 SimpleInstallFunction(prototype, "getHours", | |
1294 Builtins::kDatePrototypeGetHours, 0, true); | |
1295 SimpleInstallFunction(prototype, "setHours", | |
1296 Builtins::kDatePrototypeSetHours, 4, false); | |
1297 SimpleInstallFunction(prototype, "getMilliseconds", | |
1298 Builtins::kDatePrototypeGetMilliseconds, 0, true); | |
1299 SimpleInstallFunction(prototype, "setMilliseconds", | |
1300 Builtins::kDatePrototypeSetMilliseconds, 1, false); | |
1301 SimpleInstallFunction(prototype, "getMinutes", | |
1302 Builtins::kDatePrototypeGetMinutes, 0, true); | |
1303 SimpleInstallFunction(prototype, "setMinutes", | |
1304 Builtins::kDatePrototypeSetMinutes, 3, false); | |
1305 SimpleInstallFunction(prototype, "getMonth", | |
1306 Builtins::kDatePrototypeGetMonth, 0, true); | |
1307 SimpleInstallFunction(prototype, "setMonth", | |
1308 Builtins::kDatePrototypeSetMonth, 2, false); | |
1309 SimpleInstallFunction(prototype, "getSeconds", | |
1310 Builtins::kDatePrototypeGetSeconds, 0, true); | |
1311 SimpleInstallFunction(prototype, "setSeconds", | |
1312 Builtins::kDatePrototypeSetSeconds, 2, false); | |
1313 SimpleInstallFunction(prototype, "getTime", Builtins::kDatePrototypeGetTime, | |
1314 0, true); | |
1315 SimpleInstallFunction(prototype, "setTime", Builtins::kDatePrototypeSetTime, | |
1316 1, false); | |
1317 SimpleInstallFunction(prototype, "getTimezoneOffset", | |
1318 Builtins::kDatePrototypeGetTimezoneOffset, 0, true); | |
1319 SimpleInstallFunction(prototype, "getUTCDate", | |
1320 Builtins::kDatePrototypeGetUTCDate, 0, true); | |
1321 SimpleInstallFunction(prototype, "setUTCDate", | |
1322 Builtins::kDatePrototypeSetUTCDate, 1, false); | |
1323 SimpleInstallFunction(prototype, "getUTCDay", | |
1324 Builtins::kDatePrototypeGetUTCDay, 0, true); | |
1325 SimpleInstallFunction(prototype, "getUTCFullYear", | |
1326 Builtins::kDatePrototypeGetUTCFullYear, 0, true); | |
1327 SimpleInstallFunction(prototype, "setUTCFullYear", | |
1328 Builtins::kDatePrototypeSetUTCFullYear, 3, false); | |
1329 SimpleInstallFunction(prototype, "getUTCHours", | |
1330 Builtins::kDatePrototypeGetUTCHours, 0, true); | |
1331 SimpleInstallFunction(prototype, "setUTCHours", | |
1332 Builtins::kDatePrototypeSetUTCHours, 4, false); | |
1333 SimpleInstallFunction(prototype, "getUTCMilliseconds", | |
1334 Builtins::kDatePrototypeGetUTCMilliseconds, 0, true); | |
1335 SimpleInstallFunction(prototype, "setUTCMilliseconds", | |
1336 Builtins::kDatePrototypeSetUTCMilliseconds, 1, false); | |
1337 SimpleInstallFunction(prototype, "getUTCMinutes", | |
1338 Builtins::kDatePrototypeGetUTCMinutes, 0, true); | |
1339 SimpleInstallFunction(prototype, "setUTCMinutes", | |
1340 Builtins::kDatePrototypeSetUTCMinutes, 3, false); | |
1341 SimpleInstallFunction(prototype, "getUTCMonth", | |
1342 Builtins::kDatePrototypeGetUTCMonth, 0, true); | |
1343 SimpleInstallFunction(prototype, "setUTCMonth", | |
1344 Builtins::kDatePrototypeSetUTCMonth, 2, false); | |
1345 SimpleInstallFunction(prototype, "getUTCSeconds", | |
1346 Builtins::kDatePrototypeGetUTCSeconds, 0, true); | |
1347 SimpleInstallFunction(prototype, "setUTCSeconds", | |
1348 Builtins::kDatePrototypeSetUTCSeconds, 2, false); | |
1349 SimpleInstallFunction(prototype, "valueOf", Builtins::kDatePrototypeValueOf, | |
1350 0, false); | |
1351 SimpleInstallFunction(prototype, "getYear", Builtins::kDatePrototypeGetYear, | |
1352 0, true); | |
1353 SimpleInstallFunction(prototype, "setYear", Builtins::kDatePrototypeSetYear, | |
1354 1, false); | |
1355 | |
1356 // Install i18n fallback functions. | |
1357 SimpleInstallFunction(prototype, "toLocaleString", | |
1358 Builtins::kDatePrototypeToString, 0, false); | |
1359 SimpleInstallFunction(prototype, "toLocaleDateString", | |
1360 Builtins::kDatePrototypeToDateString, 0, false); | |
1361 SimpleInstallFunction(prototype, "toLocaleTimeString", | |
1362 Builtins::kDatePrototypeToTimeString, 0, false); | |
1363 | |
1364 // Install the @@toPrimitive function. | |
1365 Handle<JSFunction> to_primitive = InstallFunction( | |
1366 prototype, factory->to_primitive_symbol(), JS_OBJECT_TYPE, | |
1367 JSObject::kHeaderSize, MaybeHandle<JSObject>(), | |
1368 Builtins::kDatePrototypeToPrimitive, | |
1369 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); | |
1370 | |
1371 // Set the expected parameters for @@toPrimitive to 1; required by builtin. | |
1372 to_primitive->shared()->set_internal_formal_parameter_count(1); | |
1373 | |
1374 // Set the length for the function to satisfy ECMA-262. | |
1375 to_primitive->shared()->set_length(1); | |
1376 } | 1258 } |
1377 | 1259 |
1378 { // -- R e g E x p | 1260 { // -- R e g E x p |
1379 // Builtin functions for RegExp.prototype. | 1261 // Builtin functions for RegExp.prototype. |
1380 Handle<JSFunction> regexp_fun = | 1262 Handle<JSFunction> regexp_fun = |
1381 InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize, | 1263 InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize, |
1382 isolate->initial_object_prototype(), | 1264 isolate->initial_object_prototype(), |
1383 Builtins::kIllegal); | 1265 Builtins::kIllegal); |
1384 InstallWithIntrinsicDefaultProto(isolate, regexp_fun, | 1266 InstallWithIntrinsicDefaultProto(isolate, regexp_fun, |
1385 Context::REGEXP_FUNCTION_INDEX); | 1267 Context::REGEXP_FUNCTION_INDEX); |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1738 } | 1620 } |
1739 | 1621 |
1740 { | 1622 { |
1741 // Set up the call-as-constructor delegate. | 1623 // Set up the call-as-constructor delegate. |
1742 Handle<Code> code = isolate->builtins()->HandleApiCallAsConstructor(); | 1624 Handle<Code> code = isolate->builtins()->HandleApiCallAsConstructor(); |
1743 Handle<JSFunction> delegate = factory->NewFunction( | 1625 Handle<JSFunction> delegate = factory->NewFunction( |
1744 factory->empty_string(), code, JS_OBJECT_TYPE, JSObject::kHeaderSize); | 1626 factory->empty_string(), code, JS_OBJECT_TYPE, JSObject::kHeaderSize); |
1745 native_context()->set_call_as_constructor_delegate(*delegate); | 1627 native_context()->set_call_as_constructor_delegate(*delegate); |
1746 delegate->shared()->DontAdaptArguments(); | 1628 delegate->shared()->DontAdaptArguments(); |
1747 } | 1629 } |
1748 } // NOLINT(readability/fn_size) | 1630 } |
1749 | 1631 |
1750 | 1632 |
1751 void Genesis::InstallTypedArray(const char* name, ElementsKind elements_kind, | 1633 void Genesis::InstallTypedArray(const char* name, ElementsKind elements_kind, |
1752 Handle<JSFunction>* fun) { | 1634 Handle<JSFunction>* fun) { |
1753 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); | 1635 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); |
1754 Handle<JSFunction> result = InstallFunction( | 1636 Handle<JSFunction> result = InstallFunction( |
1755 global, name, JS_TYPED_ARRAY_TYPE, JSTypedArray::kSize, | 1637 global, name, JS_TYPED_ARRAY_TYPE, JSTypedArray::kSize, |
1756 isolate()->initial_object_prototype(), Builtins::kIllegal); | 1638 isolate()->initial_object_prototype(), Builtins::kIllegal); |
1757 | 1639 |
1758 Handle<Map> initial_map = isolate()->factory()->NewMap( | 1640 Handle<Map> initial_map = isolate()->factory()->NewMap( |
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2642 HeapObject::cast(string_function->initial_map()->prototype())->map()); | 2524 HeapObject::cast(string_function->initial_map()->prototype())->map()); |
2643 | 2525 |
2644 // Install Global.eval. | 2526 // Install Global.eval. |
2645 { | 2527 { |
2646 Handle<JSFunction> eval = SimpleInstallFunction( | 2528 Handle<JSFunction> eval = SimpleInstallFunction( |
2647 handle(native_context()->global_object()), factory()->eval_string(), | 2529 handle(native_context()->global_object()), factory()->eval_string(), |
2648 Builtins::kGlobalEval, 1, false); | 2530 Builtins::kGlobalEval, 1, false); |
2649 native_context()->set_global_eval_fun(*eval); | 2531 native_context()->set_global_eval_fun(*eval); |
2650 } | 2532 } |
2651 | 2533 |
| 2534 // Setup the Date constructor. |
| 2535 { |
| 2536 Handle<String> key = factory()->Date_string(); |
| 2537 Handle<JSFunction> date_fun = Handle<JSFunction>::cast( |
| 2538 Object::GetProperty(handle(native_context()->global_object()), key) |
| 2539 .ToHandleChecked()); |
| 2540 Handle<JSObject> prototype = |
| 2541 Handle<JSObject>(JSObject::cast(date_fun->instance_prototype())); |
| 2542 |
| 2543 // Install the Date.now, Date.parse and Date.UTC functions. |
| 2544 SimpleInstallFunction(date_fun, "now", Builtins::kDateNow, 0, false); |
| 2545 SimpleInstallFunction(date_fun, "parse", Builtins::kDateParse, 1, false); |
| 2546 SimpleInstallFunction(date_fun, "UTC", Builtins::kDateUTC, 7, false); |
| 2547 |
| 2548 // Install the "constructor" property on the {prototype}. |
| 2549 JSObject::AddProperty(prototype, factory()->constructor_string(), date_fun, |
| 2550 DONT_ENUM); |
| 2551 |
| 2552 // Install the toISOString and valueOf functions. |
| 2553 SimpleInstallFunction(prototype, "toISOString", |
| 2554 Builtins::kDatePrototypeToISOString, 0, false); |
| 2555 SimpleInstallFunction(prototype, "getDate", Builtins::kDatePrototypeGetDate, |
| 2556 0, true); |
| 2557 SimpleInstallFunction(prototype, "getDay", Builtins::kDatePrototypeGetDay, |
| 2558 0, true); |
| 2559 SimpleInstallFunction(prototype, "getFullYear", |
| 2560 Builtins::kDatePrototypeGetFullYear, 0, true); |
| 2561 SimpleInstallFunction(prototype, "getHours", |
| 2562 Builtins::kDatePrototypeGetHours, 0, true); |
| 2563 SimpleInstallFunction(prototype, "getMilliseconds", |
| 2564 Builtins::kDatePrototypeGetMilliseconds, 0, true); |
| 2565 SimpleInstallFunction(prototype, "getMinutes", |
| 2566 Builtins::kDatePrototypeGetMinutes, 0, true); |
| 2567 SimpleInstallFunction(prototype, "getMonth", |
| 2568 Builtins::kDatePrototypeGetMonth, 0, true); |
| 2569 SimpleInstallFunction(prototype, "getSeconds", |
| 2570 Builtins::kDatePrototypeGetSeconds, 0, true); |
| 2571 SimpleInstallFunction(prototype, "getTime", Builtins::kDatePrototypeGetTime, |
| 2572 0, true); |
| 2573 SimpleInstallFunction(prototype, "getTimezoneOffset", |
| 2574 Builtins::kDatePrototypeGetTimezoneOffset, 0, true); |
| 2575 SimpleInstallFunction(prototype, "getUTCDate", |
| 2576 Builtins::kDatePrototypeGetUTCDate, 0, true); |
| 2577 SimpleInstallFunction(prototype, "getUTCDay", |
| 2578 Builtins::kDatePrototypeGetUTCDay, 0, true); |
| 2579 SimpleInstallFunction(prototype, "getUTCFullYear", |
| 2580 Builtins::kDatePrototypeGetUTCFullYear, 0, true); |
| 2581 SimpleInstallFunction(prototype, "getUTCHours", |
| 2582 Builtins::kDatePrototypeGetUTCHours, 0, true); |
| 2583 SimpleInstallFunction(prototype, "getUTCMilliseconds", |
| 2584 Builtins::kDatePrototypeGetUTCMilliseconds, 0, true); |
| 2585 SimpleInstallFunction(prototype, "getUTCMinutes", |
| 2586 Builtins::kDatePrototypeGetUTCMinutes, 0, true); |
| 2587 SimpleInstallFunction(prototype, "getUTCMonth", |
| 2588 Builtins::kDatePrototypeGetUTCMonth, 0, true); |
| 2589 SimpleInstallFunction(prototype, "getUTCSeconds", |
| 2590 Builtins::kDatePrototypeGetUTCSeconds, 0, true); |
| 2591 SimpleInstallFunction(prototype, "valueOf", Builtins::kDatePrototypeValueOf, |
| 2592 0, false); |
| 2593 |
| 2594 // Install the @@toPrimitive function. |
| 2595 Handle<JSFunction> to_primitive = InstallFunction( |
| 2596 prototype, factory()->to_primitive_symbol(), JS_OBJECT_TYPE, |
| 2597 JSObject::kHeaderSize, MaybeHandle<JSObject>(), |
| 2598 Builtins::kDatePrototypeToPrimitive, |
| 2599 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); |
| 2600 |
| 2601 // Set the expected parameters for @@toPrimitive to 1; required by builtin. |
| 2602 to_primitive->shared()->set_internal_formal_parameter_count(1); |
| 2603 |
| 2604 // Set the length for the function to satisfy ECMA-262. |
| 2605 to_primitive->shared()->set_length(1); |
| 2606 } |
| 2607 |
2652 // Install Array.prototype.concat | 2608 // Install Array.prototype.concat |
2653 { | 2609 { |
2654 Handle<JSFunction> array_constructor(native_context()->array_function()); | 2610 Handle<JSFunction> array_constructor(native_context()->array_function()); |
2655 Handle<JSObject> proto(JSObject::cast(array_constructor->prototype())); | 2611 Handle<JSObject> proto(JSObject::cast(array_constructor->prototype())); |
2656 Handle<JSFunction> concat = | 2612 Handle<JSFunction> concat = |
2657 InstallFunction(proto, "concat", JS_OBJECT_TYPE, JSObject::kHeaderSize, | 2613 InstallFunction(proto, "concat", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
2658 MaybeHandle<JSObject>(), Builtins::kArrayConcat); | 2614 MaybeHandle<JSObject>(), Builtins::kArrayConcat); |
2659 | 2615 |
2660 // Make sure that Array.prototype.concat appears to be compiled. | 2616 // Make sure that Array.prototype.concat appears to be compiled. |
2661 // The code will never be called, but inline caching for call will | 2617 // The code will never be called, but inline caching for call will |
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3515 } | 3471 } |
3516 | 3472 |
3517 | 3473 |
3518 // Called when the top-level V8 mutex is destroyed. | 3474 // Called when the top-level V8 mutex is destroyed. |
3519 void Bootstrapper::FreeThreadResources() { | 3475 void Bootstrapper::FreeThreadResources() { |
3520 DCHECK(!IsActive()); | 3476 DCHECK(!IsActive()); |
3521 } | 3477 } |
3522 | 3478 |
3523 } // namespace internal | 3479 } // namespace internal |
3524 } // namespace v8 | 3480 } // namespace v8 |
OLD | NEW |