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

Side by Side Diff: src/bootstrapper.cc

Issue 2142933003: Move Error methods to C++ (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Move to builtins-error.cc Created 4 years, 5 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
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/ieee754.h" 9 #include "src/base/ieee754.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 968
969 static void InstallWithIntrinsicDefaultProto(Isolate* isolate, 969 static void InstallWithIntrinsicDefaultProto(Isolate* isolate,
970 Handle<JSFunction> function, 970 Handle<JSFunction> function,
971 int context_index) { 971 int context_index) {
972 Handle<Smi> index(Smi::FromInt(context_index), isolate); 972 Handle<Smi> index(Smi::FromInt(context_index), isolate);
973 JSObject::AddProperty( 973 JSObject::AddProperty(
974 function, isolate->factory()->native_context_index_symbol(), index, NONE); 974 function, isolate->factory()->native_context_index_symbol(), index, NONE);
975 isolate->native_context()->set(context_index, *function); 975 isolate->native_context()->set(context_index, *function);
976 } 976 }
977 977
978 static void InstallError(Isolate* isolate, Handle<JSObject> global,
979 Handle<String> name, int context_index) {
980 Factory* factory = isolate->factory();
981
982 Handle<JSFunction> error_fun =
983 InstallFunction(global, name, JS_ERROR_TYPE, JSObject::kHeaderSize,
984 isolate->initial_object_prototype(),
985 Builtins::kErrorConstructor, DONT_ENUM);
986 error_fun->shared()->set_instance_class_name(*factory->Error_string());
987 error_fun->shared()->DontAdaptArguments();
988 error_fun->shared()->set_construct_stub(
989 *isolate->builtins()->ErrorConstructor());
990 error_fun->shared()->set_length(1);
991 error_fun->shared()->set_native(true);
992
993 if (context_index == Context::ERROR_FUNCTION_INDEX) {
994 Handle<JSFunction> capture_stack_trace_fun =
995 SimpleInstallFunction(error_fun, "captureStackTrace",
996 Builtins::kErrorCaptureStackTrace, 2, false);
997 capture_stack_trace_fun->shared()->set_native(true);
998 }
999
1000 InstallWithIntrinsicDefaultProto(isolate, error_fun, context_index);
1001
1002 {
1003 Handle<JSObject> prototype =
1004 factory->NewJSObject(isolate->object_function(), TENURED);
1005
1006 JSObject::AddProperty(prototype, factory->name_string(), name, DONT_ENUM);
1007 JSObject::AddProperty(prototype, factory->message_string(),
1008 factory->empty_string(), DONT_ENUM);
1009 JSObject::AddProperty(prototype, factory->constructor_string(), error_fun,
1010 DONT_ENUM);
1011
1012 Handle<JSFunction> to_string_fun =
1013 SimpleInstallFunction(prototype, factory->toString_string(),
1014 Builtins::kErrorPrototypeToString, 0, true);
1015 to_string_fun->shared()->set_native(true);
1016
1017 if (context_index != Context::ERROR_FUNCTION_INDEX) {
1018 Handle<JSFunction> global_error = isolate->error_function();
1019 CHECK(JSReceiver::SetPrototype(error_fun, global_error, false,
1020 Object::THROW_ON_ERROR)
1021 .FromMaybe(false));
1022 CHECK(JSReceiver::SetPrototype(prototype,
1023 handle(global_error->prototype(), isolate),
1024 false, Object::THROW_ON_ERROR)
1025 .FromMaybe(false));
1026 }
1027
1028 Accessors::FunctionSetPrototype(error_fun, prototype).Assert();
1029 }
1030
1031 Handle<Map> initial_map(error_fun->initial_map());
1032 Map::EnsureDescriptorSlack(initial_map, 1);
1033
1034 PropertyAttributes attribs = DONT_ENUM;
1035 Handle<AccessorInfo> error_stack =
1036 Accessors::ErrorStackInfo(isolate, attribs);
1037 {
1038 AccessorConstantDescriptor d(Handle<Name>(Name::cast(error_stack->name())),
1039 error_stack, attribs);
1040 initial_map->AppendDescriptor(&d);
1041 }
1042 }
978 1043
979 // This is only called if we are not using snapshots. The equivalent 1044 // This is only called if we are not using snapshots. The equivalent
980 // work in the snapshot case is done in HookUpGlobalObject. 1045 // work in the snapshot case is done in HookUpGlobalObject.
981 void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, 1046 void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
982 Handle<JSFunction> empty_function, 1047 Handle<JSFunction> empty_function,
983 GlobalContextType context_type) { 1048 GlobalContextType context_type) {
984 // --- N a t i v e C o n t e x t --- 1049 // --- N a t i v e C o n t e x t ---
985 // Use the empty function as closure (no scope info). 1050 // Use the empty function as closure (no scope info).
986 native_context()->set_closure(*empty_function); 1051 native_context()->set_closure(*empty_function);
987 native_context()->set_previous(NULL); 1052 native_context()->set_previous(NULL);
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
1511 initial_map->AppendDescriptor(&field); 1576 initial_map->AppendDescriptor(&field);
1512 1577
1513 static const int num_fields = JSRegExp::kInObjectFieldCount; 1578 static const int num_fields = JSRegExp::kInObjectFieldCount;
1514 initial_map->SetInObjectProperties(num_fields); 1579 initial_map->SetInObjectProperties(num_fields);
1515 initial_map->set_unused_property_fields(0); 1580 initial_map->set_unused_property_fields(0);
1516 initial_map->set_instance_size(initial_map->instance_size() + 1581 initial_map->set_instance_size(initial_map->instance_size() +
1517 num_fields * kPointerSize); 1582 num_fields * kPointerSize);
1518 } 1583 }
1519 1584
1520 { // -- E r r o r 1585 { // -- E r r o r
1521 Handle<JSFunction> error_fun = InstallFunction( 1586 InstallError(isolate, global, factory->Error_string(),
1522 global, "Error", JS_ERROR_TYPE, JSObject::kHeaderSize, 1587 Context::ERROR_FUNCTION_INDEX);
1523 isolate->initial_object_prototype(), Builtins::kIllegal);
1524 InstallWithIntrinsicDefaultProto(isolate, error_fun,
1525 Context::ERROR_FUNCTION_INDEX);
1526 } 1588 }
1527 1589
1528 { // -- E v a l E r r o r 1590 { // -- E v a l E r r o r
1529 Handle<JSFunction> eval_error_fun = InstallFunction( 1591 InstallError(isolate, global, factory->EvalError_string(),
1530 global, "EvalError", JS_ERROR_TYPE, JSObject::kHeaderSize, 1592 Context::EVAL_ERROR_FUNCTION_INDEX);
1531 isolate->initial_object_prototype(), Builtins::kIllegal);
1532 InstallWithIntrinsicDefaultProto(isolate, eval_error_fun,
1533 Context::EVAL_ERROR_FUNCTION_INDEX);
1534 } 1593 }
1535 1594
1536 { // -- R a n g e E r r o r 1595 { // -- R a n g e E r r o r
1537 Handle<JSFunction> range_error_fun = InstallFunction( 1596 InstallError(isolate, global, factory->RangeError_string(),
1538 global, "RangeError", JS_ERROR_TYPE, JSObject::kHeaderSize, 1597 Context::RANGE_ERROR_FUNCTION_INDEX);
1539 isolate->initial_object_prototype(), Builtins::kIllegal);
1540 InstallWithIntrinsicDefaultProto(isolate, range_error_fun,
1541 Context::RANGE_ERROR_FUNCTION_INDEX);
1542 } 1598 }
1543 1599
1544 { // -- R e f e r e n c e E r r o r 1600 { // -- R e f e r e n c e E r r o r
1545 Handle<JSFunction> reference_error_fun = InstallFunction( 1601 InstallError(isolate, global, factory->ReferenceError_string(),
1546 global, "ReferenceError", JS_ERROR_TYPE, JSObject::kHeaderSize, 1602 Context::REFERENCE_ERROR_FUNCTION_INDEX);
1547 isolate->initial_object_prototype(), Builtins::kIllegal);
1548 InstallWithIntrinsicDefaultProto(isolate, reference_error_fun,
1549 Context::REFERENCE_ERROR_FUNCTION_INDEX);
1550 } 1603 }
1551 1604
1552 { // -- S y n t a x E r r o r 1605 { // -- S y n t a x E r r o r
1553 Handle<JSFunction> syntax_error_fun = InstallFunction( 1606 InstallError(isolate, global, factory->SyntaxError_string(),
1554 global, "SyntaxError", JS_ERROR_TYPE, JSObject::kHeaderSize, 1607 Context::SYNTAX_ERROR_FUNCTION_INDEX);
1555 isolate->initial_object_prototype(), Builtins::kIllegal);
1556 InstallWithIntrinsicDefaultProto(isolate, syntax_error_fun,
1557 Context::SYNTAX_ERROR_FUNCTION_INDEX);
1558 } 1608 }
1559 1609
1560 { // -- T y p e E r r o r 1610 { // -- T y p e E r r o r
1561 Handle<JSFunction> type_error_fun = InstallFunction( 1611 InstallError(isolate, global, factory->TypeError_string(),
1562 global, "TypeError", JS_ERROR_TYPE, JSObject::kHeaderSize, 1612 Context::TYPE_ERROR_FUNCTION_INDEX);
1563 isolate->initial_object_prototype(), Builtins::kIllegal);
1564 InstallWithIntrinsicDefaultProto(isolate, type_error_fun,
1565 Context::TYPE_ERROR_FUNCTION_INDEX);
1566 } 1613 }
1567 1614
1568 { // -- U R I E r r o r 1615 { // -- U R I E r r o r
1569 Handle<JSFunction> uri_error_fun = InstallFunction( 1616 InstallError(isolate, global, factory->URIError_string(),
1570 global, "URIError", JS_ERROR_TYPE, JSObject::kHeaderSize, 1617 Context::URI_ERROR_FUNCTION_INDEX);
1571 isolate->initial_object_prototype(), Builtins::kIllegal);
1572 InstallWithIntrinsicDefaultProto(isolate, uri_error_fun,
1573 Context::URI_ERROR_FUNCTION_INDEX);
1574 } 1618 }
1575 1619
1576 // Initialize the embedder data slot. 1620 // Initialize the embedder data slot.
1577 Handle<FixedArray> embedder_data = factory->NewFixedArray(3); 1621 Handle<FixedArray> embedder_data = factory->NewFixedArray(3);
1578 native_context()->set_embedder_data(*embedder_data); 1622 native_context()->set_embedder_data(*embedder_data);
1579 1623
1580 { // -- J S O N 1624 { // -- J S O N
1581 Handle<String> name = factory->InternalizeUtf8String("JSON"); 1625 Handle<String> name = factory->InternalizeUtf8String("JSON");
1582 Handle<JSFunction> cons = factory->NewFunction(name); 1626 Handle<JSFunction> cons = factory->NewFunction(name);
1583 JSFunction::SetInstancePrototype(cons, 1627 JSFunction::SetInstancePrototype(cons,
(...skipping 2376 matching lines...) Expand 10 before | Expand all | Expand 10 after
3960 } 4004 }
3961 4005
3962 4006
3963 // Called when the top-level V8 mutex is destroyed. 4007 // Called when the top-level V8 mutex is destroyed.
3964 void Bootstrapper::FreeThreadResources() { 4008 void Bootstrapper::FreeThreadResources() {
3965 DCHECK(!IsActive()); 4009 DCHECK(!IsActive());
3966 } 4010 }
3967 4011
3968 } // namespace internal 4012 } // namespace internal
3969 } // namespace v8 4013 } // namespace v8
OLDNEW
« src/accessors.cc ('K') | « src/accessors.cc ('k') | src/builtins/builtins.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698