Chromium Code Reviews| Index: src/js/messages.js |
| diff --git a/src/js/messages.js b/src/js/messages.js |
| index 8db1166ff472ef1853ba579fc21268057230d10a..a15f3cb200197ba74a933aed477660603c8b05dd 100644 |
| --- a/src/js/messages.js |
| +++ b/src/js/messages.js |
| @@ -908,36 +908,22 @@ var StackTraceSetter = function(v) { |
| var captureStackTrace = function() {}; |
| -// Define special error type constructors. |
| -function DefineError(global, f) { |
| - // Store the error function in both the global object |
| - // and the runtime object. The function is fetched |
| - // from the runtime object when throwing errors from |
| - // within the runtime system to avoid strange side |
| - // effects when overwriting the error functions from |
| - // user code. |
| - var name = f.name; |
| - %AddNamedProperty(global, name, f, DONT_ENUM); |
| - // Configure the error function. |
| - if (name == 'Error') { |
| - // The prototype of the Error object must itself be an error. |
| - // However, it can't be an instance of the Error object because |
| - // it hasn't been properly configured yet. Instead we create a |
| - // special not-a-true-error-but-close-enough object. |
| - var ErrorPrototype = function() {}; |
| - %FunctionSetPrototype(ErrorPrototype, GlobalObject.prototype); |
| - %FunctionSetInstanceClassName(ErrorPrototype, 'Error'); |
| - %FunctionSetPrototype(f, new ErrorPrototype()); |
| - } else { |
| - %FunctionSetPrototype(f, new GlobalError()); |
| - %InternalSetPrototype(f, GlobalError); |
| - } |
| - %FunctionSetInstanceClassName(f, 'Error'); |
| - %AddNamedProperty(f.prototype, 'constructor', f, DONT_ENUM); |
| - %AddNamedProperty(f.prototype, 'name', name, DONT_ENUM); |
| - %SetCode(f, function(m) { |
| +// Set up special error type constructors. |
| +function SetUpError(error_function) { |
| + %FunctionSetInstanceClassName(error_function, 'Error'); |
| + var name = error_function.name; |
| + %AddNamedProperty(error_function.prototype, 'name', name, DONT_ENUM); |
|
Igor Sheludko
2015/12/04 17:06:10
Why not set the prototype up in the bootstrapper?
|
| + %AddNamedProperty(error_function.prototype, 'message', '', DONT_ENUM); |
| + %AddNamedProperty(error_function.prototype, 'constructor', error_function, DONT_ENUM); |
|
Igor Sheludko
2015/12/04 17:06:10
Line longer than 80 chars.
|
| + |
| + // TODO(verwaest): NativeError.prototype should not have .toString, but this |
| + // currently fails. |
| + utils.InstallFunctions(error_function.prototype, DONT_ENUM, |
| + ['toString', ErrorToString]); |
| + |
| + %SetCode(error_function, function(m) { |
| if (!IS_UNDEFINED(new.target)) { |
| - try { captureStackTrace(this, f); } catch (e) { } |
| + try { captureStackTrace(this, error_function); } catch (e) { } |
| // Define all the expected properties directly on the error |
| // object. This avoids going through getters and setters defined |
| // on prototype objects. |
| @@ -945,25 +931,21 @@ function DefineError(global, f) { |
| %AddNamedProperty(this, 'message', TO_STRING(m), DONT_ENUM); |
| } |
| } else { |
| - return new f(m); |
| + return new error_function(m); |
| } |
| }); |
| - %SetNativeFlag(f); |
| - return f; |
| -}; |
| -GlobalError = DefineError(global, function Error() { }); |
| -GlobalEvalError = DefineError(global, function EvalError() { }); |
| -GlobalRangeError = DefineError(global, function RangeError() { }); |
| -GlobalReferenceError = DefineError(global, function ReferenceError() { }); |
| -GlobalSyntaxError = DefineError(global, function SyntaxError() { }); |
| -GlobalTypeError = DefineError(global, function TypeError() { }); |
| -GlobalURIError = DefineError(global, function URIError() { }); |
| - |
| -%AddNamedProperty(GlobalError.prototype, 'message', '', DONT_ENUM); |
| + %SetNativeFlag(error_function); |
| + return error_function; |
| +}; |
| -utils.InstallFunctions(GlobalError.prototype, DONT_ENUM, |
| - ['toString', ErrorToString]); |
| +GlobalError = SetUpError(global.Error); |
| +GlobalEvalError = SetUpError(global.EvalError); |
| +GlobalRangeError = SetUpError(global.RangeError); |
| +GlobalReferenceError = SetUpError(global.ReferenceError); |
| +GlobalSyntaxError = SetUpError(global.SyntaxError); |
| +GlobalTypeError = SetUpError(global.TypeError); |
| +GlobalURIError = SetUpError(global.URIError); |
| function ErrorToString() { |
| if (!IS_SPEC_OBJECT(this)) { |
| @@ -1011,8 +993,6 @@ captureStackTrace = function captureStackTrace(obj, cons_opt) { |
| GlobalError.captureStackTrace = captureStackTrace; |
| %InstallToContext([ |
| - "error_function", GlobalError, |
| - "eval_error_function", GlobalEvalError, |
| "get_stack_trace_line_fun", GetStackTraceLine, |
| "make_error_function", MakeGenericError, |
| "make_range_error", MakeRangeError, |
| @@ -1021,13 +1001,8 @@ GlobalError.captureStackTrace = captureStackTrace; |
| "message_get_line_number", GetLineNumber, |
| "message_get_source_line", GetSourceLine, |
| "no_side_effect_to_string_fun", NoSideEffectToString, |
| - "range_error_function", GlobalRangeError, |
| - "reference_error_function", GlobalReferenceError, |
| "stack_overflow_boilerplate", StackOverflowBoilerplate, |
| - "syntax_error_function", GlobalSyntaxError, |
| "to_detail_string_fun", ToDetailString, |
| - "type_error_function", GlobalTypeError, |
| - "uri_error_function", GlobalURIError, |
| ]); |
| utils.Export(function(to) { |