Chromium Code Reviews| Index: src/messages.js |
| diff --git a/src/messages.js b/src/messages.js |
| index cbb5000d7d07f1b69421b3d44f6ba85b0bc13aac..17369ca36225ce163357bb561794c63b4851cc1d 100644 |
| --- a/src/messages.js |
| +++ b/src/messages.js |
| @@ -746,64 +746,72 @@ function GetPositionInLine(message) { |
| function GetStackTraceLine(recv, fun, pos, isGlobal) { |
| - return new CallSite(recv, fun, pos).toString(); |
| + return new CallSite(recv, fun, pos, false).toString(); |
| } |
| // ---------------------------------------------------------------------------- |
| // Error implementation |
| -function CallSite(receiver, fun, pos) { |
| - this.receiver = receiver; |
| - this.fun = fun; |
| - this.pos = pos; |
| +var CallSiteReceiverKey = %CreateSymbol("receiver"); |
|
rossberg
2013/03/28 10:04:33
Nit: do our coding conventions allow this kind of
|
| +var CallSiteFunctionKey = %CreateSymbol("function"); |
| +var CallSitePositionKey = %CreateSymbol("position"); |
| +var CallSiteStrictModeKey = %CreateSymbol("strict mode"); |
| + |
| +function CallSite(receiver, fun, pos, strict_mode) { |
| + this[CallSiteReceiverKey] = receiver; |
| + this[CallSiteFunctionKey] = fun; |
| + this[CallSitePositionKey] = pos; |
| + this[CallSiteStrictModeKey] = strict_mode; |
| } |
| function CallSiteGetThis() { |
| - return this.receiver; |
| + if (this[CallSiteStrictModeKey]) return void 0; |
|
rossberg
2013/03/28 10:04:33
You could use ?: here.
|
| + return this[CallSiteReceiverKey]; |
| } |
| function CallSiteGetTypeName() { |
| - return GetTypeName(this, false); |
| + return GetTypeName(this[CallSiteReceiverKey], false); |
| } |
| function CallSiteIsToplevel() { |
| - if (this.receiver == null) { |
| + if (this[CallSiteReceiverKey] == null) { |
| return true; |
| } |
| - return IS_GLOBAL(this.receiver); |
| + return IS_GLOBAL(this[CallSiteReceiverKey]); |
| } |
| function CallSiteIsEval() { |
| - var script = %FunctionGetScript(this.fun); |
| + var script = %FunctionGetScript(this[CallSiteFunctionKey]); |
| return script && script.compilation_type == COMPILATION_TYPE_EVAL; |
| } |
| function CallSiteGetEvalOrigin() { |
| - var script = %FunctionGetScript(this.fun); |
| + var script = %FunctionGetScript(this[CallSiteFunctionKey]); |
| return FormatEvalOrigin(script); |
| } |
| function CallSiteGetScriptNameOrSourceURL() { |
| - var script = %FunctionGetScript(this.fun); |
| + var script = %FunctionGetScript(this[CallSiteFunctionKey]); |
| return script ? script.nameOrSourceURL() : null; |
| } |
| function CallSiteGetFunction() { |
| - return this.fun; |
| + if (this[CallSiteStrictModeKey]) return void 0; |
|
rossberg
2013/03/28 10:04:33
...same here.
|
| + return this[CallSiteFunctionKey]; |
| } |
| function CallSiteGetFunctionName() { |
| // See if the function knows its own name |
| - var name = this.fun.name; |
| + var name = this[CallSiteFunctionKey].name; |
| if (name) { |
| return name; |
| } |
| - name = %FunctionGetInferredName(this.fun); |
| + name = %FunctionGetInferredName(this[CallSiteFunctionKey]); |
| if (name) { |
| return name; |
| } |
| // Maybe this is an evaluation? |
| - var script = %FunctionGetScript(this.fun); |
| + var script = %FunctionGetScript(this[CallSiteFunctionKey]); |
| if (script && script.compilation_type == COMPILATION_TYPE_EVAL) { |
| return "eval"; |
| } |
| @@ -813,26 +821,22 @@ function CallSiteGetFunctionName() { |
| function CallSiteGetMethodName() { |
| // See if we can find a unique property on the receiver that holds |
| // this function. |
| - var ownName = this.fun.name; |
| - if (ownName && this.receiver && |
| - (%_CallFunction(this.receiver, |
| - ownName, |
| - ObjectLookupGetter) === this.fun || |
| - %_CallFunction(this.receiver, |
| - ownName, |
| - ObjectLookupSetter) === this.fun || |
| - (IS_OBJECT(this.receiver) && |
| - %GetDataProperty(this.receiver, ownName) === this.fun))) { |
| + var receiver = this[CallSiteReceiverKey]; |
| + var fun = this[CallSiteFunctionKey]; |
| + var ownName = fun.name; |
| + if (ownName && receiver && |
| + (%_CallFunction(receiver, ownName, ObjectLookupGetter) === fun || |
| + %_CallFunction(receiver, ownName, ObjectLookupSetter) === fun || |
| + (IS_OBJECT(receiver) && %GetDataProperty(receiver, ownName) === fun))) { |
| // To handle DontEnum properties we guess that the method has |
| // the same name as the function. |
| return ownName; |
| } |
| var name = null; |
| - for (var prop in this.receiver) { |
| - if (%_CallFunction(this.receiver, prop, ObjectLookupGetter) === this.fun || |
| - %_CallFunction(this.receiver, prop, ObjectLookupSetter) === this.fun || |
| - (IS_OBJECT(this.receiver) && |
| - %GetDataProperty(this.receiver, prop) === this.fun)) { |
| + for (var prop in receiver) { |
| + if (%_CallFunction(receiver, prop, ObjectLookupGetter) === fun || |
| + %_CallFunction(receiver, prop, ObjectLookupSetter) === fun || |
| + (IS_OBJECT(receiver) && %GetDataProperty(receiver, prop) === fun)) { |
| // If we find more than one match bail out to avoid confusion. |
| if (name) { |
| return null; |
| @@ -847,49 +851,49 @@ function CallSiteGetMethodName() { |
| } |
| function CallSiteGetFileName() { |
| - var script = %FunctionGetScript(this.fun); |
| + var script = %FunctionGetScript(this[CallSiteFunctionKey]); |
| return script ? script.name : null; |
| } |
| function CallSiteGetLineNumber() { |
| - if (this.pos == -1) { |
| + if (this[CallSitePositionKey] == -1) { |
| return null; |
| } |
| - var script = %FunctionGetScript(this.fun); |
| + var script = %FunctionGetScript(this[CallSiteFunctionKey]); |
| var location = null; |
| if (script) { |
| - location = script.locationFromPosition(this.pos, true); |
| + location = script.locationFromPosition(this[CallSitePositionKey], true); |
| } |
| return location ? location.line + 1 : null; |
| } |
| function CallSiteGetColumnNumber() { |
| - if (this.pos == -1) { |
| + if (this[CallSitePositionKey] == -1) { |
| return null; |
| } |
| - var script = %FunctionGetScript(this.fun); |
| + var script = %FunctionGetScript(this[CallSiteFunctionKey]); |
| var location = null; |
| if (script) { |
| - location = script.locationFromPosition(this.pos, true); |
| + location = script.locationFromPosition(this[CallSitePositionKey], true); |
| } |
| return location ? location.column + 1: null; |
| } |
| function CallSiteIsNative() { |
| - var script = %FunctionGetScript(this.fun); |
| + var script = %FunctionGetScript(this[CallSiteFunctionKey]); |
| return script ? (script.type == TYPE_NATIVE) : false; |
| } |
| function CallSiteGetPosition() { |
| - return this.pos; |
| + return this[CallSitePositionKey]; |
| } |
| function CallSiteIsConstructor() { |
| - var receiver = this.receiver; |
| + var receiver = this[CallSiteReceiverKey]; |
| var constructor = |
| IS_OBJECT(receiver) ? %GetDataProperty(receiver, "constructor") : null; |
| if (!constructor) return false; |
| - return this.fun === constructor; |
| + return this[CallSiteFunctionKey] === constructor; |
| } |
| function CallSiteToString() { |
| @@ -932,7 +936,7 @@ function CallSiteToString() { |
| var isConstructor = this.isConstructor(); |
| var isMethodCall = !(this.isToplevel() || isConstructor); |
| if (isMethodCall) { |
| - var typeName = GetTypeName(this, true); |
| + var typeName = GetTypeName([CallSiteReceiverKey], true); |
| var methodName = this.getMethodName(); |
| if (functionName) { |
| if (typeName && |
| @@ -1036,13 +1040,16 @@ function FormatErrorString(error) { |
| function GetStackFrames(raw_stack) { |
| var frames = new InternalArray(); |
| - for (var i = 0; i < raw_stack.length; i += 4) { |
| + var non_strict_frames = raw_stack[0]; |
| + for (var i = 1; i < raw_stack.length; i += 4) { |
| var recv = raw_stack[i]; |
| var fun = raw_stack[i + 1]; |
| var code = raw_stack[i + 2]; |
| var pc = raw_stack[i + 3]; |
| var pos = %FunctionGetPositionForOffset(code, pc); |
| - frames.push(new CallSite(recv, fun, pos)); |
| + non_strict_frames--; |
| + var strict_mode = (non_strict_frames < 0); |
| + frames.push(new CallSite(recv, fun, pos, strict_mode)); |
|
rossberg
2013/03/28 10:04:33
Could inline def of strict_mode here.
|
| } |
| return frames; |
| } |
| @@ -1070,16 +1077,16 @@ function FormatStackTrace(error_string, frames) { |
| } |
| -function GetTypeName(obj, requireConstructor) { |
| - var constructor = obj.receiver.constructor; |
| +function GetTypeName(receiver, requireConstructor) { |
| + var constructor = receiver.constructor; |
| if (!constructor) { |
| return requireConstructor ? null : |
| - %_CallFunction(obj.receiver, ObjectToString); |
| + %_CallFunction(receiver, ObjectToString); |
| } |
| var constructorName = constructor.name; |
| if (!constructorName) { |
| return requireConstructor ? null : |
| - %_CallFunction(obj.receiver, ObjectToString); |
| + %_CallFunction(receiver, ObjectToString); |
| } |
| return constructorName; |
| } |