[Webkit-unassigned] [Bug 131707] Simple ES6 feature: Number constructor extras

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sun Sep 28 18:10:55 PDT 2014


https://bugs.webkit.org/show_bug.cgi?id=131707





--- Comment #34 from Darin Adler <darin at apple.com>  2014-09-28 18:10:50 PST ---
(From update of attachment 238593)
View in context: https://bugs.webkit.org/attachment.cgi?id=238593&action=review

>>>> LayoutTests/js/script-tests/number-constructor.js:22
>>>> +shouldBeFalse('Number.isFinite(undefined)');
>>> 
>>> Just for your information, there is no keyword “undefined”. This just works because undefined is not the name of any variable or property. Could also be “foo”, which is also undefined.
>> 
>> I looked a bit into this. It seems "undefined" is a property of the global object, so it's a variable in the global scope. The value of "undefined" is the primitive value undefined. You're correct when you say "undefined" is not a reserved-word in JavaScript. It would be possible to do "var undefined = 10;", although this property of the global object is non-writable, non-configurable, so it has no effect.
>> 
>> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined
>> 
>> Number.isFinite(foo) wouldn't work because "foo" is not defined as a variable yet (throws Exception ReferenceError). Number.isFinite(undefined) is the same as Number.isFinite(), in both cases the argument the function isFinite(x) receives will be undefined.
>> 
>> For all the functions (except in the cases of parseInt and parseFloat), there was already a test for testing a function without arguments and calling it with "undefined" . Since it is the same thing, I will remove the "undefined" calls. I will add a test for calling a function with a not defined variable, should throw an Exception.
> 
> Happily ES spec does now define an immutable property named "undefined" with the value undefined on the global object!
> 
> Yay!
> 
> Alas it's still not a keyword so 
> function f(undefined) { if (typeof blah === undefined) ... }
> 
> Is still horribly broken, but if you do that you deserve whatever pain you get :)

Got it. That window object property named "undefined" is new since I learned JavaScript.

>>> LayoutTests/js/script-tests/number-constructor.js:121
>>> +shouldBe('Number.parseFloat(null)', 'NaN');
>> 
>> no test of undefined for parseFloat?
> 
> Same thing as Number.parseFloat().

I don’t think you understand my question. Inside the engine, it’s possible for Number.parseFloat() and Number.parseFloat(variableWithUndefinedValue) to work differently. Functions defined in the JavaScript language treat them the same way, but it’s possible to make an error and treat them differently, so both should be tested.

For example, there are functions in the HTML DOM that treat them differently (much to my chagrin).

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the webkit-unassigned mailing list