Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #30506
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | arguments object in strict mode (was: null variable issue???) |
| Date | 2016-05-22 07:23 +0200 |
| Organization | PointedEars Software (PES) |
| Message-ID | <2066481.kK9x2ueqWy@PointedEars.de> (permalink) |
| References | <d247ae48-6485-40e6-8063-ae3797422142@googlegroups.com> <64f704db-05a1-48a5-b107-6d8425090f0e@googlegroups.com> <oy5fyi8p1oou.n88uyzgd3k3p.dlg@40tude.net> <1592358.q6somyMhXi@PointedEars.de> |
Thomas 'PointedEars' Lahn wrote:
> JJ wrote:
>> On Fri, 20 May 2016 06:29:57 -0700 (PDT), helixpoint@gmail.com wrote:
>>> On Friday, May 20, 2016 at 7:45:35 AM UTC-4, helix...@gmail.com wrote:
>>>> This is the line. Can't I use...&& to stop this from returning null
>>>>
>>>> return (E.Util.ieVersion() < 9 ? a.caller : a.caller.caller);
>>>>
>>>> I know this is wrong, but something like....
>>>>
>>>> return (E.Util.ieVersion() < 9 ? &&a.caller : &&a.caller.caller);
>>>
>>> If both object are null in the ternary, I get an error because it is
>>> looking for a true or false returned. If it is null, I need to return
>>> true
>>
>> Use this then.
>>
>> return (E.Util.ieVersion() < 9 ? a.caller : a.caller.caller) || true;
>
> It is a mistake to depend on browser sniffing when there are more reliable
> alternatives. The OP is probably having an X–Y problem, attempting to fix
> with this a problem that occurred only because of a wrong approach.
JFTR:
It appears that V8 has been changed so that the deprecated “caller” property
is now a property of the “arguments” object even in strict mode, but as
specified for strict mode the direct (not typeof-like) property (read)
access to “arguments.caller” throws an exception.
There had not been a “caller” property in strict mode, so the approach to
avoid the strict mode violation using feature tests was successful.
This caused me to commit the following workaround to the stack trace
generator, jsx.getStackTrace(), today:
-------------------------------------------------------------------------------
diff --git a/object.js b/object.js
index b341e99..a585fa8 100644
--- a/object.js
+++ b/object.js
@@ -2429,34 +2429,8 @@ de.pointedears.jsx = jsx;
var result = '';
- var caller =
- (jsx.object._hasOwnProperty(jsx_getStackTrace, "caller") &&
jsx_getStackTrace.caller)
- || (jsx.object._hasOwnProperty(arguments, "caller") &&
arguments.caller);
-
- if (caller)
+ if (typeof Error == "function")
{
- /* JScript and older JavaScript */
- while (caller != null)
- {
- result += '> ' + (jsx.object.getFunctionName(caller, true) ||
"anonymous")
- + '\n';
- if (caller.caller == caller)
- {
- result += '*';
- break;
- }
-
- caller = caller.caller;
- }
- }
- else
- {
- /* other */
- if (typeof Error != "function")
- {
- return result;
- }
-
var stack = parseErrorStack(new Error());
result = stack.slice(2).join("\n");
// for (var i = 1; i < stack.length; i++)
@@ -2465,6 +2439,35 @@ de.pointedears.jsx = jsx;
// }
}
+ /*
+ * Avoid strict violation; implementations with Error should also have
+ * the “stack” property
+ */
+ /* FIXME: Use local strict mode declaration only */
+ if (!stack)
+ {
+ /* JScript and older JavaScript */
+ var caller =
+ (jsx.object._hasOwnProperty(jsx_getStackTrace, "caller") &&
jsx_getStackTrace.caller)
+ || (jsx.object._hasOwnProperty(arguments, "caller") &&
arguments.caller);
+
+ if (caller)
+ {
+ while (caller != null)
+ {
+ result += '> ' + (jsx.object.getFunctionName(caller, true) ||
"anonymous")
+ + '\n';
+ if (caller.caller == caller)
+ {
+ result += '*';
+ break;
+ }
+
+ caller = caller.caller;
+ }
+ }
+ }
+
return result;
};
-------------------------------------------------------------------------------
It is only a temporary workaround because the problem occured now because I
had made the mistake of declaring strict mode *globally* before. AISB, this
is a bad idea as then all code that is executed after the declaration runs
in strict mode, and it might not be written to that – especially if the code
is third-party code.
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
null variable issue??? helixpoint@gmail.com - 2016-05-20 04:45 -0700
Re: null variable issue??? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-05-20 05:21 -0700
Re: null variable issue??? helixpoint@gmail.com - 2016-05-20 05:42 -0700
Re: null variable issue??? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-05-20 06:05 -0700
Re: null variable issue??? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-05-20 14:10 +0100
Re: null variable issue??? helixpoint@gmail.com - 2016-05-20 06:29 -0700
Re: null variable issue??? JJ <jj4public@vfemail.net> - 2016-05-20 20:53 +0700
Re: null variable issue??? JJ <jj4public@vfemail.net> - 2016-05-20 20:55 +0700
Re: null variable issue??? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-05-20 21:06 +0200
arguments object in strict mode (was: null variable issue???) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-05-22 07:23 +0200
Re: null variable issue??? JJ <jj4public@vfemail.net> - 2016-05-20 20:46 +0700
csiph-web