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/base/ieee754.h" | 9 #include "src/base/ieee754.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 1293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1304 { // --- N u m b e r --- | 1304 { // --- N u m b e r --- |
1305 Handle<JSFunction> number_fun = InstallFunction( | 1305 Handle<JSFunction> number_fun = InstallFunction( |
1306 global, "Number", JS_VALUE_TYPE, JSValue::kSize, | 1306 global, "Number", JS_VALUE_TYPE, JSValue::kSize, |
1307 isolate->initial_object_prototype(), Builtins::kNumberConstructor); | 1307 isolate->initial_object_prototype(), Builtins::kNumberConstructor); |
1308 number_fun->shared()->DontAdaptArguments(); | 1308 number_fun->shared()->DontAdaptArguments(); |
1309 number_fun->shared()->set_construct_stub( | 1309 number_fun->shared()->set_construct_stub( |
1310 *isolate->builtins()->NumberConstructor_ConstructStub()); | 1310 *isolate->builtins()->NumberConstructor_ConstructStub()); |
1311 number_fun->shared()->set_length(1); | 1311 number_fun->shared()->set_length(1); |
1312 InstallWithIntrinsicDefaultProto(isolate, number_fun, | 1312 InstallWithIntrinsicDefaultProto(isolate, number_fun, |
1313 Context::NUMBER_FUNCTION_INDEX); | 1313 Context::NUMBER_FUNCTION_INDEX); |
| 1314 |
| 1315 // Create the %NumberPrototype% |
| 1316 Handle<JSValue> prototype = |
| 1317 Handle<JSValue>::cast(factory->NewJSObject(number_fun, TENURED)); |
| 1318 prototype->set_value(Smi::FromInt(0)); |
| 1319 Accessors::FunctionSetPrototype(number_fun, prototype).Assert(); |
| 1320 |
| 1321 // Install the "constructor" property on the {prototype}. |
| 1322 JSObject::AddProperty(prototype, factory->constructor_string(), number_fun, |
| 1323 DONT_ENUM); |
| 1324 |
| 1325 // Install the Number.prototype methods. |
| 1326 SimpleInstallFunction(prototype, "toExponential", |
| 1327 Builtins::kNumberPrototypeToExponential, 1, false); |
| 1328 SimpleInstallFunction(prototype, "toFixed", |
| 1329 Builtins::kNumberPrototypeToFixed, 1, false); |
| 1330 SimpleInstallFunction(prototype, "toPrecision", |
| 1331 Builtins::kNumberPrototypeToPrecision, 1, false); |
| 1332 SimpleInstallFunction(prototype, "toString", |
| 1333 Builtins::kNumberPrototypeToString, 1, false); |
| 1334 SimpleInstallFunction(prototype, "valueOf", |
| 1335 Builtins::kNumberPrototypeValueOf, 0, true); |
| 1336 |
| 1337 // Install i18n fallback functions. |
| 1338 SimpleInstallFunction(prototype, "toLocaleString", |
| 1339 Builtins::kNumberPrototypeToLocaleString, 0, false); |
1314 } | 1340 } |
1315 | 1341 |
1316 { // --- B o o l e a n --- | 1342 { // --- B o o l e a n --- |
1317 Handle<JSFunction> boolean_fun = | 1343 Handle<JSFunction> boolean_fun = |
1318 InstallFunction(global, "Boolean", JS_VALUE_TYPE, JSValue::kSize, | 1344 InstallFunction(global, "Boolean", JS_VALUE_TYPE, JSValue::kSize, |
1319 isolate->initial_object_prototype(), | 1345 isolate->initial_object_prototype(), |
1320 Builtins::kBooleanConstructor); | 1346 Builtins::kBooleanConstructor); |
1321 boolean_fun->shared()->DontAdaptArguments(); | 1347 boolean_fun->shared()->DontAdaptArguments(); |
1322 boolean_fun->shared()->set_construct_stub( | 1348 boolean_fun->shared()->set_construct_stub( |
1323 *isolate->builtins()->BooleanConstructor_ConstructStub()); | 1349 *isolate->builtins()->BooleanConstructor_ConstructStub()); |
1324 boolean_fun->shared()->set_length(1); | 1350 boolean_fun->shared()->set_length(1); |
1325 InstallWithIntrinsicDefaultProto(isolate, boolean_fun, | 1351 InstallWithIntrinsicDefaultProto(isolate, boolean_fun, |
1326 Context::BOOLEAN_FUNCTION_INDEX); | 1352 Context::BOOLEAN_FUNCTION_INDEX); |
1327 | 1353 |
1328 // Create the %BooleanPrototype% | 1354 // Create the %BooleanPrototype% |
1329 Handle<JSValue> prototype = | 1355 Handle<JSValue> prototype = |
1330 Handle<JSValue>::cast(factory->NewJSObject(boolean_fun, TENURED)); | 1356 Handle<JSValue>::cast(factory->NewJSObject(boolean_fun, TENURED)); |
1331 prototype->set_value(isolate->heap()->false_value()); | 1357 prototype->set_value(isolate->heap()->false_value()); |
1332 Accessors::FunctionSetPrototype(boolean_fun, prototype).Assert(); | 1358 Accessors::FunctionSetPrototype(boolean_fun, prototype).Assert(); |
1333 | 1359 |
1334 // Install the "constructor" property on the {prototype}. | 1360 // Install the "constructor" property on the {prototype}. |
1335 JSObject::AddProperty(prototype, factory->constructor_string(), boolean_fun, | 1361 JSObject::AddProperty(prototype, factory->constructor_string(), boolean_fun, |
1336 DONT_ENUM); | 1362 DONT_ENUM); |
1337 | 1363 |
1338 // Install the Boolean.prototype methods. | 1364 // Install the Boolean.prototype methods. |
1339 SimpleInstallFunction(prototype, "toString", | 1365 SimpleInstallFunction(prototype, "toString", |
1340 Builtins::kBooleanPrototypeToString, 0, false); | 1366 Builtins::kBooleanPrototypeToString, 0, true); |
1341 SimpleInstallFunction(prototype, "valueOf", | 1367 SimpleInstallFunction(prototype, "valueOf", |
1342 Builtins::kBooleanPrototypeValueOf, 0, false); | 1368 Builtins::kBooleanPrototypeValueOf, 0, true); |
1343 } | 1369 } |
1344 | 1370 |
1345 { // --- S t r i n g --- | 1371 { // --- S t r i n g --- |
1346 Handle<JSFunction> string_fun = InstallFunction( | 1372 Handle<JSFunction> string_fun = InstallFunction( |
1347 global, "String", JS_VALUE_TYPE, JSValue::kSize, | 1373 global, "String", JS_VALUE_TYPE, JSValue::kSize, |
1348 isolate->initial_object_prototype(), Builtins::kStringConstructor); | 1374 isolate->initial_object_prototype(), Builtins::kStringConstructor); |
1349 string_fun->shared()->set_construct_stub( | 1375 string_fun->shared()->set_construct_stub( |
1350 *isolate->builtins()->StringConstructor_ConstructStub()); | 1376 *isolate->builtins()->StringConstructor_ConstructStub()); |
1351 string_fun->shared()->DontAdaptArguments(); | 1377 string_fun->shared()->DontAdaptArguments(); |
1352 string_fun->shared()->set_length(1); | 1378 string_fun->shared()->set_length(1); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1385 | 1411 |
1386 // Install the "constructor" property on the {prototype}. | 1412 // Install the "constructor" property on the {prototype}. |
1387 JSObject::AddProperty(prototype, factory->constructor_string(), string_fun, | 1413 JSObject::AddProperty(prototype, factory->constructor_string(), string_fun, |
1388 DONT_ENUM); | 1414 DONT_ENUM); |
1389 | 1415 |
1390 // Install the String.prototype methods. | 1416 // Install the String.prototype methods. |
1391 SimpleInstallFunction(prototype, "charAt", Builtins::kStringPrototypeCharAt, | 1417 SimpleInstallFunction(prototype, "charAt", Builtins::kStringPrototypeCharAt, |
1392 1, true); | 1418 1, true); |
1393 SimpleInstallFunction(prototype, "charCodeAt", | 1419 SimpleInstallFunction(prototype, "charCodeAt", |
1394 Builtins::kStringPrototypeCharCodeAt, 1, true); | 1420 Builtins::kStringPrototypeCharCodeAt, 1, true); |
| 1421 SimpleInstallFunction(prototype, "toString", |
| 1422 Builtins::kStringPrototypeToString, 0, true); |
1395 SimpleInstallFunction(prototype, "trim", Builtins::kStringPrototypeTrim, 0, | 1423 SimpleInstallFunction(prototype, "trim", Builtins::kStringPrototypeTrim, 0, |
1396 false); | 1424 false); |
1397 SimpleInstallFunction(prototype, "trimLeft", | 1425 SimpleInstallFunction(prototype, "trimLeft", |
1398 Builtins::kStringPrototypeTrimLeft, 0, false); | 1426 Builtins::kStringPrototypeTrimLeft, 0, false); |
1399 SimpleInstallFunction(prototype, "trimRight", | 1427 SimpleInstallFunction(prototype, "trimRight", |
1400 Builtins::kStringPrototypeTrimRight, 0, false); | 1428 Builtins::kStringPrototypeTrimRight, 0, false); |
| 1429 SimpleInstallFunction(prototype, "valueOf", |
| 1430 Builtins::kStringPrototypeValueOf, 0, true); |
1401 } | 1431 } |
1402 | 1432 |
1403 { | 1433 { |
1404 // --- S y m b o l --- | 1434 // --- S y m b o l --- |
1405 Handle<JSObject> prototype = | 1435 Handle<JSObject> prototype = |
1406 factory->NewJSObject(isolate->object_function(), TENURED); | 1436 factory->NewJSObject(isolate->object_function(), TENURED); |
1407 Handle<JSFunction> symbol_fun = | 1437 Handle<JSFunction> symbol_fun = |
1408 InstallFunction(global, "Symbol", JS_VALUE_TYPE, JSValue::kSize, | 1438 InstallFunction(global, "Symbol", JS_VALUE_TYPE, JSValue::kSize, |
1409 prototype, Builtins::kSymbolConstructor); | 1439 prototype, Builtins::kSymbolConstructor); |
1410 symbol_fun->shared()->set_construct_stub( | 1440 symbol_fun->shared()->set_construct_stub( |
1411 *isolate->builtins()->SymbolConstructor_ConstructStub()); | 1441 *isolate->builtins()->SymbolConstructor_ConstructStub()); |
1412 symbol_fun->shared()->set_length(0); | 1442 symbol_fun->shared()->set_length(0); |
1413 symbol_fun->shared()->DontAdaptArguments(); | 1443 symbol_fun->shared()->DontAdaptArguments(); |
1414 native_context()->set_symbol_function(*symbol_fun); | 1444 native_context()->set_symbol_function(*symbol_fun); |
1415 | 1445 |
| 1446 // Install the @@toStringTag property on the {prototype}. |
| 1447 JSObject::AddProperty( |
| 1448 prototype, factory->to_string_tag_symbol(), |
| 1449 factory->NewStringFromAsciiChecked("Symbol"), |
| 1450 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); |
| 1451 |
1416 // Install the "constructor" property on the {prototype}. | 1452 // Install the "constructor" property on the {prototype}. |
1417 JSObject::AddProperty(prototype, factory->constructor_string(), symbol_fun, | 1453 JSObject::AddProperty(prototype, factory->constructor_string(), symbol_fun, |
1418 DONT_ENUM); | 1454 DONT_ENUM); |
| 1455 |
| 1456 // Install the Symbol.prototype methods. |
| 1457 SimpleInstallFunction(prototype, "toString", |
| 1458 Builtins::kSymbolPrototypeToString, 0, true); |
| 1459 SimpleInstallFunction(prototype, "valueOf", |
| 1460 Builtins::kSymbolPrototypeValueOf, 0, true); |
| 1461 |
| 1462 // Install the @@toPrimitive function. |
| 1463 Handle<JSFunction> to_primitive = InstallFunction( |
| 1464 prototype, factory->to_primitive_symbol(), JS_OBJECT_TYPE, |
| 1465 JSObject::kHeaderSize, MaybeHandle<JSObject>(), |
| 1466 Builtins::kSymbolPrototypeToPrimitive, |
| 1467 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); |
| 1468 |
| 1469 // Set the expected parameters for @@toPrimitive to 1; required by builtin. |
| 1470 to_primitive->shared()->set_internal_formal_parameter_count(1); |
| 1471 |
| 1472 // Set the length for the function to satisfy ECMA-262. |
| 1473 to_primitive->shared()->set_length(1); |
1419 } | 1474 } |
1420 | 1475 |
1421 { // --- D a t e --- | 1476 { // --- D a t e --- |
1422 // Builtin functions for Date.prototype. | 1477 // Builtin functions for Date.prototype. |
1423 Handle<JSObject> prototype = | 1478 Handle<JSObject> prototype = |
1424 factory->NewJSObject(isolate->object_function(), TENURED); | 1479 factory->NewJSObject(isolate->object_function(), TENURED); |
1425 Handle<JSFunction> date_fun = | 1480 Handle<JSFunction> date_fun = |
1426 InstallFunction(global, "Date", JS_DATE_TYPE, JSDate::kSize, prototype, | 1481 InstallFunction(global, "Date", JS_DATE_TYPE, JSDate::kSize, prototype, |
1427 Builtins::kDateConstructor); | 1482 Builtins::kDateConstructor); |
1428 InstallWithIntrinsicDefaultProto(isolate, date_fun, | 1483 InstallWithIntrinsicDefaultProto(isolate, date_fun, |
(...skipping 2526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3955 } | 4010 } |
3956 | 4011 |
3957 | 4012 |
3958 // Called when the top-level V8 mutex is destroyed. | 4013 // Called when the top-level V8 mutex is destroyed. |
3959 void Bootstrapper::FreeThreadResources() { | 4014 void Bootstrapper::FreeThreadResources() { |
3960 DCHECK(!IsActive()); | 4015 DCHECK(!IsActive()); |
3961 } | 4016 } |
3962 | 4017 |
3963 } // namespace internal | 4018 } // namespace internal |
3964 } // namespace v8 | 4019 } // namespace v8 |
OLD | NEW |