Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #30491 > unrolled thread

null variable issue???

Started byhelixpoint@gmail.com
First post2016-05-20 04:45 -0700
Last post2016-05-20 20:46 +0700
Articles 11 — 5 participants

Back to article view | Back to comp.lang.javascript


Contents

  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

#30491 — null variable issue???

Fromhelixpoint@gmail.com
Date2016-05-20 04:45 -0700
Subjectnull variable issue???
Message-ID<d247ae48-6485-40e6-8063-ae3797422142@googlegroups.com>
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);

[toc] | [next] | [standalone]


#30493

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2016-05-20 05:21 -0700
Message-ID<8c666bbc-b2cf-4b34-9c35-4a7fba74584d@googlegroups.com>
In reply to#30491
On Friday, May 20, 2016 at 6:45:35 AM UTC-5, 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);

You have to be certain that everything you are dispatching on is not null

Also, You should not be writing code targeting a specific browser. Browsers lie. Finally, there is no reason to use caller. Refactor your code

[toc] | [prev] | [next] | [standalone]


#30495

Fromhelixpoint@gmail.com
Date2016-05-20 05:42 -0700
Message-ID<1aaa235c-121b-4bdd-af96-081693f06a0d@googlegroups.com>
In reply to#30491
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);

Both are returning null. How do I return false if both are null

[toc] | [prev] | [next] | [standalone]


#30496

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2016-05-20 06:05 -0700
Message-ID<5d868e2c-36f9-410f-b1b9-a72c36242c99@googlegroups.com>
In reply to#30495
On Friday, May 20, 2016 at 7:42:34 AM UTC-5, helix...@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);
> 
> Both are returning null. How do I return false if both are null

both of what? have you identified which object is returning null?  I'm assuming caller (which you shouldn't be using anyway).

null instanceof Object === false

as does 

null || false

[toc] | [prev] | [next] | [standalone]


#30497

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2016-05-20 14:10 +0100
Message-ID<87zirkub6m.fsf@bsb.me.uk>
In reply to#30495
helixpoint@gmail.com writes:

> 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);

What's the && about?  That looks like a syntax error.

> Both are returning null. How do I return false if both are null

You probably think that's clear, but it's not.  To what two things does
"both" refer?

But I will repeat the advice you've had: test for browser versions, and
using "caller" are both signs that something is amiss elsewhere.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#30498

Fromhelixpoint@gmail.com
Date2016-05-20 06:29 -0700
Message-ID<64f704db-05a1-48a5-b107-6d8425090f0e@googlegroups.com>
In reply to#30491
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

[toc] | [prev] | [next] | [standalone]


#30500

FromJJ <jj4public@vfemail.net>
Date2016-05-20 20:53 +0700
Message-ID<1ci36dwczs658.1afx06ngzi23g$.dlg@40tude.net>
In reply to#30498
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

If it needs to return a boolean type based on whether the function caller
are null or non null, use this:

  return !!(E.Util.ieVersion() < 9 ? a.caller : a.caller.caller);

[toc] | [prev] | [next] | [standalone]


#30501

FromJJ <jj4public@vfemail.net>
Date2016-05-20 20:55 +0700
Message-ID<oy5fyi8p1oou.n88uyzgd3k3p.dlg@40tude.net>
In reply to#30498
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;

[toc] | [prev] | [next] | [standalone]


#30502

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2016-05-20 21:06 +0200
Message-ID<1592358.q6somyMhXi@PointedEars.de>
In reply to#30501
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.

-- 
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.

[toc] | [prev] | [next] | [standalone]


#30506 — arguments object in strict mode (was: null variable issue???)

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2016-05-22 07:23 +0200
Subjectarguments object in strict mode (was: null variable issue???)
Message-ID<2066481.kK9x2ueqWy@PointedEars.de>
In reply to#30502
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.

[toc] | [prev] | [next] | [standalone]


#30499

FromJJ <jj4public@vfemail.net>
Date2016-05-20 20:46 +0700
Message-ID<19u6kv1agiruf.1szhdzfzdmxpe.dlg@40tude.net>
In reply to#30491
On Fri, 20 May 2016 04:45:30 -0700 (PDT), helixpoint@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);

"E.Util.ieVersion()" returns any number depending on the browser version.
"a.caller" is null if "a" is an event handler.
"a.caller.caller" is null if "a.caller" is an event handler.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web