Chromium Code Reviews| Index: src/bootstrapper.cc |
| diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc |
| index 3c00a5e09867d442b67526e32da5b6bfea3360ed..ce5faafeca83ae2539bb865cdc49f69fabc42bad 100644 |
| --- a/src/bootstrapper.cc |
| +++ b/src/bootstrapper.cc |
| @@ -1116,6 +1116,71 @@ static void InstallWithIntrinsicDefaultProto(Isolate* isolate, |
| isolate->native_context()->set(context_index, *function); |
| } |
| +static void InstallError(Isolate* isolate, Handle<JSObject> global, |
| + Handle<String> name, int context_index) { |
| + Factory* factory = isolate->factory(); |
| + |
| + Handle<JSFunction> error_fun = |
| + InstallFunction(global, name, JS_ERROR_TYPE, JSObject::kHeaderSize, |
| + isolate->initial_object_prototype(), |
| + Builtins::kErrorConstructor, DONT_ENUM); |
| + error_fun->shared()->set_instance_class_name(*factory->Error_string()); |
| + error_fun->shared()->DontAdaptArguments(); |
| + error_fun->shared()->set_construct_stub( |
| + *isolate->builtins()->ErrorConstructor()); |
| + error_fun->shared()->set_length(1); |
| + error_fun->shared()->set_native(true); |
| + |
| + if (context_index == Context::ERROR_FUNCTION_INDEX) { |
| + Handle<JSFunction> capture_stack_trace_fun = |
| + SimpleInstallFunction(error_fun, "captureStackTrace", |
| + Builtins::kErrorCaptureStackTrace, 2, false); |
| + capture_stack_trace_fun->shared()->set_native(true); |
| + } |
| + |
| + InstallWithIntrinsicDefaultProto(isolate, error_fun, context_index); |
| + |
| + { |
| + Handle<JSObject> prototype = |
| + factory->NewJSObject(isolate->object_function(), TENURED); |
| + |
| + JSObject::AddProperty(prototype, factory->name_string(), name, DONT_ENUM); |
| + JSObject::AddProperty(prototype, factory->message_string(), |
| + factory->empty_string(), DONT_ENUM); |
| + JSObject::AddProperty(prototype, factory->constructor_string(), error_fun, |
| + DONT_ENUM); |
| + |
| + Handle<JSFunction> to_string_fun = |
| + SimpleInstallFunction(prototype, factory->toString_string(), |
| + Builtins::kErrorPrototypeToString, 0, true); |
| + to_string_fun->shared()->set_native(true); |
| + |
| + if (context_index != Context::ERROR_FUNCTION_INDEX) { |
| + Handle<JSFunction> globalError = isolate->error_function(); |
|
Yang
2016/07/15 13:10:11
let's name this "global_error" to be consistent wi
jgruber
2016/07/18 13:06:11
Done.
|
| + CHECK(JSReceiver::SetPrototype(error_fun, globalError, false, |
| + Object::THROW_ON_ERROR) |
| + .FromMaybe(false)); |
| + CHECK(JSReceiver::SetPrototype(prototype, |
| + handle(globalError->prototype(), isolate), |
| + false, Object::THROW_ON_ERROR) |
| + .FromMaybe(false)); |
| + } |
| + |
| + Accessors::FunctionSetPrototype(error_fun, prototype).Assert(); |
| + } |
| + |
| + Handle<Map> initial_map(error_fun->initial_map()); |
| + Map::EnsureDescriptorSlack(initial_map, 1); |
| + |
| + PropertyAttributes attribs = DONT_ENUM; |
| + Handle<AccessorInfo> error_stack = |
| + Accessors::ErrorStackInfo(isolate, attribs); |
| + { |
| + AccessorConstantDescriptor d(Handle<Name>(Name::cast(error_stack->name())), |
| + error_stack, attribs); |
| + initial_map->AppendDescriptor(&d); |
| + } |
| +} |
| // This is only called if we are not using snapshots. The equivalent |
| // work in the snapshot case is done in HookUpGlobalObject. |
| @@ -1659,59 +1724,38 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, |
| } |
| { // -- E r r o r |
| - Handle<JSFunction> error_fun = InstallFunction( |
| - global, "Error", JS_ERROR_TYPE, JSObject::kHeaderSize, |
| - isolate->initial_object_prototype(), Builtins::kIllegal); |
| - InstallWithIntrinsicDefaultProto(isolate, error_fun, |
| - Context::ERROR_FUNCTION_INDEX); |
| + InstallError(isolate, global, factory->Error_string(), |
| + Context::ERROR_FUNCTION_INDEX); |
| } |
| { // -- E v a l E r r o r |
| - Handle<JSFunction> eval_error_fun = InstallFunction( |
| - global, "EvalError", JS_ERROR_TYPE, JSObject::kHeaderSize, |
| - isolate->initial_object_prototype(), Builtins::kIllegal); |
| - InstallWithIntrinsicDefaultProto(isolate, eval_error_fun, |
| - Context::EVAL_ERROR_FUNCTION_INDEX); |
| + InstallError(isolate, global, factory->EvalError_string(), |
| + Context::EVAL_ERROR_FUNCTION_INDEX); |
| } |
| { // -- R a n g e E r r o r |
| - Handle<JSFunction> range_error_fun = InstallFunction( |
| - global, "RangeError", JS_ERROR_TYPE, JSObject::kHeaderSize, |
| - isolate->initial_object_prototype(), Builtins::kIllegal); |
| - InstallWithIntrinsicDefaultProto(isolate, range_error_fun, |
| - Context::RANGE_ERROR_FUNCTION_INDEX); |
| + InstallError(isolate, global, factory->RangeError_string(), |
| + Context::RANGE_ERROR_FUNCTION_INDEX); |
| } |
| { // -- R e f e r e n c e E r r o r |
| - Handle<JSFunction> reference_error_fun = InstallFunction( |
| - global, "ReferenceError", JS_ERROR_TYPE, JSObject::kHeaderSize, |
| - isolate->initial_object_prototype(), Builtins::kIllegal); |
| - InstallWithIntrinsicDefaultProto(isolate, reference_error_fun, |
| - Context::REFERENCE_ERROR_FUNCTION_INDEX); |
| + InstallError(isolate, global, factory->ReferenceError_string(), |
| + Context::REFERENCE_ERROR_FUNCTION_INDEX); |
| } |
| { // -- S y n t a x E r r o r |
| - Handle<JSFunction> syntax_error_fun = InstallFunction( |
| - global, "SyntaxError", JS_ERROR_TYPE, JSObject::kHeaderSize, |
| - isolate->initial_object_prototype(), Builtins::kIllegal); |
| - InstallWithIntrinsicDefaultProto(isolate, syntax_error_fun, |
| - Context::SYNTAX_ERROR_FUNCTION_INDEX); |
| + InstallError(isolate, global, factory->SyntaxError_string(), |
| + Context::SYNTAX_ERROR_FUNCTION_INDEX); |
| } |
| { // -- T y p e E r r o r |
| - Handle<JSFunction> type_error_fun = InstallFunction( |
| - global, "TypeError", JS_ERROR_TYPE, JSObject::kHeaderSize, |
| - isolate->initial_object_prototype(), Builtins::kIllegal); |
| - InstallWithIntrinsicDefaultProto(isolate, type_error_fun, |
| - Context::TYPE_ERROR_FUNCTION_INDEX); |
| + InstallError(isolate, global, factory->TypeError_string(), |
| + Context::TYPE_ERROR_FUNCTION_INDEX); |
| } |
| { // -- U R I E r r o r |
| - Handle<JSFunction> uri_error_fun = InstallFunction( |
| - global, "URIError", JS_ERROR_TYPE, JSObject::kHeaderSize, |
| - isolate->initial_object_prototype(), Builtins::kIllegal); |
| - InstallWithIntrinsicDefaultProto(isolate, uri_error_fun, |
| - Context::URI_ERROR_FUNCTION_INDEX); |
| + InstallError(isolate, global, factory->URIError_string(), |
| + Context::URI_ERROR_FUNCTION_INDEX); |
| } |
| // Initialize the embedder data slot. |