Bug 170888 - test262: test262/test/built-ins/isNaN/toprimitive-not-callable-throws.js
Summary: test262: test262/test/built-ins/isNaN/toprimitive-not-callable-throws.js
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Joseph Pecoraro
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-04-16 12:24 PDT by Joseph Pecoraro
Modified: 2017-04-16 13:20 PDT (History)
7 users (show)

See Also:


Attachments
[PATCH] Proposed Fix (14.25 KB, patch)
2017-04-16 12:28 PDT, Joseph Pecoraro
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 2017-04-16 12:24:30 PDT
test262/test/built-ins/isNaN/toprimitive-not-callable-throws.js

Test:
isNaN( {[Symbol.toPrimitive]: 1} )

Expected:
Throw TypeError, Symbol.toPrimitive must be a function, undefined, or null

Actual:
true

Notes:
- Firefox: TypeError: can't convert v to number: its [Symbol.toPrimitive] property is not a function
- Chrome: TypeError: number is not a function

Spec:

https://tc39.github.io/ecma262/#sec-toprimitive
7.1.1 ToPrimitive ( input [ , PreferredType ] )

> 1. Assert: input is an ECMAScript language value.
> 2. If Type(input) is Object, then
>     a. If PreferredType was not passed, let hint be "default".
>     b. Else if PreferredType is hint String, let hint be "string".
>     c. Else PreferredType is hint Number, let hint be "number".
>     d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
>     e. If exoticToPrim is not undefined, then
>     ...

https://tc39.github.io/ecma262/#sec-getmethod
7.3.9 GetMethod ( V, P )

> 1. Assert: IsPropertyKey(P) is true.
> 2. Let func be ? GetV(V, P).
> 3. If func is either undefined or null, return undefined.
> 4. If IsCallable(func) is false, throw a TypeError exception.
> 5. Return func.

The key part here being GetMethod(..., @@toPrimitive) should throw a TypeError if the property is not callable (undefined / null handled earlier).
Comment 1 Joseph Pecoraro 2017-04-16 12:28:07 PDT
Created attachment 307234 [details]
[PATCH] Proposed Fix
Comment 2 Saam Barati 2017-04-16 13:01:50 PDT
Comment on attachment 307234 [details]
[PATCH] Proposed Fix

r=me
Comment 3 WebKit Commit Bot 2017-04-16 13:20:15 PDT
Comment on attachment 307234 [details]
[PATCH] Proposed Fix

Clearing flags on attachment: 307234

Committed r215402: <http://trac.webkit.org/changeset/215402>
Comment 4 WebKit Commit Bot 2017-04-16 13:20:16 PDT
All reviewed patches have been landed.  Closing bug.