Index: src/js/messages.js |
diff --git a/src/js/messages.js b/src/js/messages.js |
index 0cfae93f536e87b787d09dba11b3c619e3319983..166643ff75f256494b75e360214867a32a279999 100644 |
--- a/src/js/messages.js |
+++ b/src/js/messages.js |
@@ -11,138 +11,16 @@ |
// ------------------------------------------------------------------- |
// Imports |
-var ArrayJoin; |
-var Bool16x8ToString; |
-var Bool32x4ToString; |
-var Bool8x16ToString; |
-var CallSite = utils.ImportNow("CallSite"); |
-var Float32x4ToString; |
-var GlobalObject = global.Object; |
+var MakeGenericError = utils.ImportNow("make_generic_error"); |
var GlobalError = global.Error; |
-var GlobalEvalError = global.EvalError; |
var GlobalRangeError = global.RangeError; |
-var GlobalReferenceError = global.ReferenceError; |
var GlobalSyntaxError = global.SyntaxError; |
var GlobalTypeError = global.TypeError; |
var GlobalURIError = global.URIError; |
-var Int16x8ToString; |
-var Int32x4ToString; |
-var Int8x16ToString; |
-var InternalArray = utils.InternalArray; |
-var internalErrorSymbol = utils.ImportNow("internal_error_symbol"); |
-var ObjectHasOwnProperty; |
-var ObjectToString = utils.ImportNow("object_to_string"); |
var Script = utils.ImportNow("Script"); |
-var stackTraceSymbol = utils.ImportNow("stack_trace_symbol"); |
-var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); |
-var Uint16x8ToString; |
-var Uint32x4ToString; |
-var Uint8x16ToString; |
- |
-utils.Import(function(from) { |
- ArrayJoin = from.ArrayJoin; |
- Bool16x8ToString = from.Bool16x8ToString; |
- Bool32x4ToString = from.Bool32x4ToString; |
- Bool8x16ToString = from.Bool8x16ToString; |
- Float32x4ToString = from.Float32x4ToString; |
- Int16x8ToString = from.Int16x8ToString; |
- Int32x4ToString = from.Int32x4ToString; |
- Int8x16ToString = from.Int8x16ToString; |
- ObjectHasOwnProperty = from.ObjectHasOwnProperty; |
- Uint16x8ToString = from.Uint16x8ToString; |
- Uint32x4ToString = from.Uint32x4ToString; |
- Uint8x16ToString = from.Uint8x16ToString; |
-}); |
// ------------------------------------------------------------------- |
- |
- |
-function NoSideEffectsObjectToString() { |
- if (IS_UNDEFINED(this)) return "[object Undefined]"; |
- if (IS_NULL(this)) return "[object Null]"; |
- var O = TO_OBJECT(this); |
- var builtinTag = %_ClassOf(O); |
- var tag = %GetDataProperty(O, toStringTagSymbol); |
- if (!IS_STRING(tag)) { |
- tag = builtinTag; |
- } |
- return `[object ${tag}]`; |
-} |
- |
-function IsErrorObject(obj) { |
- return HAS_PRIVATE(obj, stackTraceSymbol); |
-} |
- |
-function NoSideEffectsErrorToString() { |
- var name = %GetDataProperty(this, "name"); |
- var message = %GetDataProperty(this, "message"); |
- name = IS_UNDEFINED(name) ? "Error" : NoSideEffectsToString(name); |
- message = IS_UNDEFINED(message) ? "" : NoSideEffectsToString(message); |
- if (name == "") return message; |
- if (message == "") return name; |
- return `${name}: ${message}`; |
-} |
- |
-function NoSideEffectsToString(obj) { |
- if (IS_STRING(obj)) return obj; |
- if (IS_NUMBER(obj)) return %_NumberToString(obj); |
- if (IS_BOOLEAN(obj)) return obj ? 'true' : 'false'; |
- if (IS_UNDEFINED(obj)) return 'undefined'; |
- if (IS_NULL(obj)) return 'null'; |
- if (IS_FUNCTION(obj)) { |
- var str = %FunctionToString(obj); |
- if (str.length > 128) { |
- str = %_SubString(str, 0, 111) + "...<omitted>..." + |
- %_SubString(str, str.length - 2, str.length); |
- } |
- return str; |
- } |
- if (IS_SYMBOL(obj)) return %SymbolDescriptiveString(obj); |
- if (IS_SIMD_VALUE(obj)) { |
- switch (typeof(obj)) { |
- case 'float32x4': return %_Call(Float32x4ToString, obj); |
- case 'int32x4': return %_Call(Int32x4ToString, obj); |
- case 'int16x8': return %_Call(Int16x8ToString, obj); |
- case 'int8x16': return %_Call(Int8x16ToString, obj); |
- case 'uint32x4': return %_Call(Uint32x4ToString, obj); |
- case 'uint16x8': return %_Call(Uint16x8ToString, obj); |
- case 'uint8x16': return %_Call(Uint8x16ToString, obj); |
- case 'bool32x4': return %_Call(Bool32x4ToString, obj); |
- case 'bool16x8': return %_Call(Bool16x8ToString, obj); |
- case 'bool8x16': return %_Call(Bool8x16ToString, obj); |
- } |
- } |
- |
- if (IS_RECEIVER(obj)) { |
- // When internally formatting error objects, use a side-effects-free version |
- // of Error.prototype.toString independent of the actually installed |
- // toString method. |
- if (IsErrorObject(obj) || |
- %GetDataProperty(obj, "toString") === ErrorToString) { |
- return %_Call(NoSideEffectsErrorToString, obj); |
- } |
- |
- if (%GetDataProperty(obj, "toString") === ObjectToString) { |
- var constructor = %GetDataProperty(obj, "constructor"); |
- if (IS_FUNCTION(constructor)) { |
- var constructor_name = %FunctionGetName(constructor); |
- if (constructor_name != "") return `#<${constructor_name}>`; |
- } |
- } |
- } |
- |
- return %_Call(NoSideEffectsObjectToString, obj); |
-} |
- |
- |
-function MakeGenericError(constructor, type, arg0, arg1, arg2) { |
- var error = new constructor(FormatMessage(type, arg0, arg1, arg2)); |
- error[internalErrorSymbol] = true; |
- return error; |
-} |
- |
- |
/** |
* Set up the Script function and constructor. |
*/ |
@@ -154,20 +32,6 @@ function MakeGenericError(constructor, type, arg0, arg1, arg2) { |
throw MakeError(kUnsupported); |
}); |
- |
-// Helper functions; called from the runtime system. |
-function FormatMessage(type, arg0, arg1, arg2) { |
- var arg0 = NoSideEffectsToString(arg0); |
- var arg1 = NoSideEffectsToString(arg1); |
- var arg2 = NoSideEffectsToString(arg2); |
- try { |
- return %FormatMessageString(type, arg0, arg1, arg2); |
- } catch (e) { |
- return "<error>"; |
- } |
-} |
- |
- |
function GetLineNumber(message) { |
var start_position = %MessageGetStartPosition(message); |
if (start_position == -1) return kNoLineNumberInfo; |
@@ -288,13 +152,11 @@ function MakeURIError() { |
} |
%InstallToContext([ |
- "make_error_function", MakeGenericError, |
"make_range_error", MakeRangeError, |
"make_type_error", MakeTypeError, |
"message_get_column_number", GetColumnNumber, |
"message_get_line_number", GetLineNumber, |
"message_get_source_line", GetSourceLine, |
- "no_side_effects_to_string_fun", NoSideEffectsToString, |
]); |
utils.Export(function(to) { |