| 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 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 } | 500 } |
| 501 | 501 |
| 502 Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base, | 502 Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base, |
| 503 Handle<String> name, Builtins::Name call, | 503 Handle<String> name, Builtins::Name call, |
| 504 bool adapt, BuiltinFunctionId id) { | 504 bool adapt, BuiltinFunctionId id) { |
| 505 Handle<JSFunction> fun = SimpleInstallGetter(base, name, call, adapt); | 505 Handle<JSFunction> fun = SimpleInstallGetter(base, name, call, adapt); |
| 506 fun->shared()->set_builtin_function_id(id); | 506 fun->shared()->set_builtin_function_id(id); |
| 507 return fun; | 507 return fun; |
| 508 } | 508 } |
| 509 | 509 |
| 510 void InstallConstant(Isolate* isolate, Handle<JSObject> holder, |
| 511 const char* name, Handle<Object> value) { |
| 512 JSObject::AddProperty( |
| 513 holder, isolate->factory()->NewStringFromAsciiChecked(name), value, |
| 514 static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY)); |
| 515 } |
| 516 |
| 510 } // namespace | 517 } // namespace |
| 511 | 518 |
| 512 Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) { | 519 Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) { |
| 513 // Allocate the map for function instances. Maps are allocated first and their | 520 // Allocate the map for function instances. Maps are allocated first and their |
| 514 // prototypes patched later, once empty function is created. | 521 // prototypes patched later, once empty function is created. |
| 515 | 522 |
| 516 // Functions with this map will not have a 'prototype' property, and | 523 // Functions with this map will not have a 'prototype' property, and |
| 517 // can not be used as constructors. | 524 // can not be used as constructors. |
| 518 Handle<Map> function_without_prototype_map = | 525 Handle<Map> function_without_prototype_map = |
| 519 factory()->CreateSloppyFunctionMap(FUNCTION_WITHOUT_PROTOTYPE); | 526 factory()->CreateSloppyFunctionMap(FUNCTION_WITHOUT_PROTOTYPE); |
| (...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1617 factory->NewJSObject(isolate->object_function(), TENURED); | 1624 factory->NewJSObject(isolate->object_function(), TENURED); |
| 1618 Handle<JSFunction> symbol_fun = | 1625 Handle<JSFunction> symbol_fun = |
| 1619 InstallFunction(global, "Symbol", JS_VALUE_TYPE, JSValue::kSize, | 1626 InstallFunction(global, "Symbol", JS_VALUE_TYPE, JSValue::kSize, |
| 1620 prototype, Builtins::kSymbolConstructor); | 1627 prototype, Builtins::kSymbolConstructor); |
| 1621 symbol_fun->shared()->SetConstructStub( | 1628 symbol_fun->shared()->SetConstructStub( |
| 1622 *isolate->builtins()->SymbolConstructor_ConstructStub()); | 1629 *isolate->builtins()->SymbolConstructor_ConstructStub()); |
| 1623 symbol_fun->shared()->set_length(0); | 1630 symbol_fun->shared()->set_length(0); |
| 1624 symbol_fun->shared()->DontAdaptArguments(); | 1631 symbol_fun->shared()->DontAdaptArguments(); |
| 1625 native_context()->set_symbol_function(*symbol_fun); | 1632 native_context()->set_symbol_function(*symbol_fun); |
| 1626 | 1633 |
| 1634 // Install the Symbol.for and Symbol.keyFor functions. |
| 1635 SimpleInstallFunction(symbol_fun, "for", Builtins::kSymbolFor, 1, false); |
| 1636 SimpleInstallFunction(symbol_fun, "keyFor", Builtins::kSymbolKeyFor, 1, |
| 1637 false); |
| 1638 |
| 1639 // Install well-known symbols. |
| 1640 InstallConstant(isolate, symbol_fun, "hasInstance", |
| 1641 factory->has_instance_symbol()); |
| 1642 InstallConstant(isolate, symbol_fun, "isConcatSpreadable", |
| 1643 factory->is_concat_spreadable_symbol()); |
| 1644 InstallConstant(isolate, symbol_fun, "iterator", |
| 1645 factory->iterator_symbol()); |
| 1646 InstallConstant(isolate, symbol_fun, "match", factory->match_symbol()); |
| 1647 InstallConstant(isolate, symbol_fun, "replace", factory->replace_symbol()); |
| 1648 InstallConstant(isolate, symbol_fun, "search", factory->search_symbol()); |
| 1649 InstallConstant(isolate, symbol_fun, "species", factory->species_symbol()); |
| 1650 InstallConstant(isolate, symbol_fun, "split", factory->split_symbol()); |
| 1651 InstallConstant(isolate, symbol_fun, "toPrimitive", |
| 1652 factory->to_primitive_symbol()); |
| 1653 InstallConstant(isolate, symbol_fun, "toStringTag", |
| 1654 factory->to_string_tag_symbol()); |
| 1655 InstallConstant(isolate, symbol_fun, "unscopables", |
| 1656 factory->unscopables_symbol()); |
| 1657 |
| 1627 // Install the @@toStringTag property on the {prototype}. | 1658 // Install the @@toStringTag property on the {prototype}. |
| 1628 JSObject::AddProperty( | 1659 JSObject::AddProperty( |
| 1629 prototype, factory->to_string_tag_symbol(), | 1660 prototype, factory->to_string_tag_symbol(), |
| 1630 factory->NewStringFromAsciiChecked("Symbol"), | 1661 factory->NewStringFromAsciiChecked("Symbol"), |
| 1631 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); | 1662 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); |
| 1632 | 1663 |
| 1633 // Install the "constructor" property on the {prototype}. | 1664 // Install the "constructor" property on the {prototype}. |
| 1634 JSObject::AddProperty(prototype, factory->constructor_string(), symbol_fun, | 1665 JSObject::AddProperty(prototype, factory->constructor_string(), symbol_fun, |
| 1635 DONT_ENUM); | 1666 DONT_ENUM); |
| 1636 | 1667 |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2194 SimpleInstallFunction(math, "sin", Builtins::kMathSin, 1, true); | 2225 SimpleInstallFunction(math, "sin", Builtins::kMathSin, 1, true); |
| 2195 SimpleInstallFunction(math, "sinh", Builtins::kMathSinh, 1, true); | 2226 SimpleInstallFunction(math, "sinh", Builtins::kMathSinh, 1, true); |
| 2196 SimpleInstallFunction(math, "sqrt", Builtins::kMathSqrt, 1, true); | 2227 SimpleInstallFunction(math, "sqrt", Builtins::kMathSqrt, 1, true); |
| 2197 SimpleInstallFunction(math, "tan", Builtins::kMathTan, 1, true); | 2228 SimpleInstallFunction(math, "tan", Builtins::kMathTan, 1, true); |
| 2198 SimpleInstallFunction(math, "tanh", Builtins::kMathTanh, 1, true); | 2229 SimpleInstallFunction(math, "tanh", Builtins::kMathTanh, 1, true); |
| 2199 SimpleInstallFunction(math, "trunc", Builtins::kMathTrunc, 1, true); | 2230 SimpleInstallFunction(math, "trunc", Builtins::kMathTrunc, 1, true); |
| 2200 | 2231 |
| 2201 // Install math constants. | 2232 // Install math constants. |
| 2202 double const kE = base::ieee754::exp(1.0); | 2233 double const kE = base::ieee754::exp(1.0); |
| 2203 double const kPI = 3.1415926535897932; | 2234 double const kPI = 3.1415926535897932; |
| 2204 JSObject::AddProperty( | 2235 InstallConstant(isolate, math, "E", factory->NewNumber(kE)); |
| 2205 math, factory->NewStringFromAsciiChecked("E"), factory->NewNumber(kE), | 2236 InstallConstant(isolate, math, "LN10", |
| 2206 static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY)); | 2237 factory->NewNumber(base::ieee754::log(10.0))); |
| 2207 JSObject::AddProperty( | 2238 InstallConstant(isolate, math, "LN2", |
| 2208 math, factory->NewStringFromAsciiChecked("LN10"), | 2239 factory->NewNumber(base::ieee754::log(2.0))); |
| 2209 factory->NewNumber(base::ieee754::log(10.0)), | 2240 InstallConstant(isolate, math, "LOG10E", |
| 2210 static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY)); | 2241 factory->NewNumber(base::ieee754::log10(kE))); |
| 2211 JSObject::AddProperty( | 2242 InstallConstant(isolate, math, "LOG2E", |
| 2212 math, factory->NewStringFromAsciiChecked("LN2"), | 2243 factory->NewNumber(base::ieee754::log2(kE))); |
| 2213 factory->NewNumber(base::ieee754::log(2.0)), | 2244 InstallConstant(isolate, math, "PI", factory->NewNumber(kPI)); |
| 2214 static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY)); | 2245 InstallConstant(isolate, math, "SQRT1_2", |
| 2215 JSObject::AddProperty( | 2246 factory->NewNumber(std::sqrt(0.5))); |
| 2216 math, factory->NewStringFromAsciiChecked("LOG10E"), | 2247 InstallConstant(isolate, math, "SQRT2", factory->NewNumber(std::sqrt(2.0))); |
| 2217 factory->NewNumber(base::ieee754::log10(kE)), | |
| 2218 static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY)); | |
| 2219 JSObject::AddProperty( | |
| 2220 math, factory->NewStringFromAsciiChecked("LOG2E"), | |
| 2221 factory->NewNumber(base::ieee754::log2(kE)), | |
| 2222 static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY)); | |
| 2223 JSObject::AddProperty( | |
| 2224 math, factory->NewStringFromAsciiChecked("PI"), factory->NewNumber(kPI), | |
| 2225 static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY)); | |
| 2226 JSObject::AddProperty( | |
| 2227 math, factory->NewStringFromAsciiChecked("SQRT1_2"), | |
| 2228 factory->NewNumber(std::sqrt(0.5)), | |
| 2229 static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY)); | |
| 2230 JSObject::AddProperty( | |
| 2231 math, factory->NewStringFromAsciiChecked("SQRT2"), | |
| 2232 factory->NewNumber(std::sqrt(2.0)), | |
| 2233 static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY)); | |
| 2234 JSObject::AddProperty( | 2248 JSObject::AddProperty( |
| 2235 math, factory->to_string_tag_symbol(), | 2249 math, factory->to_string_tag_symbol(), |
| 2236 factory->NewStringFromAsciiChecked("Math"), | 2250 factory->NewStringFromAsciiChecked("Math"), |
| 2237 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); | 2251 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); |
| 2238 } | 2252 } |
| 2239 | 2253 |
| 2240 { // -- A r r a y B u f f e r | 2254 { // -- A r r a y B u f f e r |
| 2241 Handle<JSFunction> array_buffer_fun = InstallArrayBuffer( | 2255 Handle<JSFunction> array_buffer_fun = InstallArrayBuffer( |
| 2242 global, "ArrayBuffer", Builtins::kArrayBufferPrototypeGetByteLength, | 2256 global, "ArrayBuffer", Builtins::kArrayBufferPrototypeGetByteLength, |
| 2243 BuiltinFunctionId::kArrayBufferByteLength); | 2257 BuiltinFunctionId::kArrayBufferByteLength); |
| (...skipping 2359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4603 } | 4617 } |
| 4604 | 4618 |
| 4605 | 4619 |
| 4606 // Called when the top-level V8 mutex is destroyed. | 4620 // Called when the top-level V8 mutex is destroyed. |
| 4607 void Bootstrapper::FreeThreadResources() { | 4621 void Bootstrapper::FreeThreadResources() { |
| 4608 DCHECK(!IsActive()); | 4622 DCHECK(!IsActive()); |
| 4609 } | 4623 } |
| 4610 | 4624 |
| 4611 } // namespace internal | 4625 } // namespace internal |
| 4612 } // namespace v8 | 4626 } // namespace v8 |
| OLD | NEW |