Bug 163437

Summary: test262: @isConstructor incorrectly thinks Math.cos is a constructor
Product: WebKit Reporter: Joseph Pecoraro <joepeck>
Component: JavaScriptCoreAssignee: Joseph Pecoraro <joepeck>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, keith_miller, mark.lam, msaboff, saam
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
[PATCH] Proposed Fix
none
[PATCH] Proposed Fix none

Description Joseph Pecoraro 2016-10-14 01:55:10 PDT
test262: @isConstructor incorrectly thinks Math.cos is a constructor
test262/test/built-ins/Array/of/return-a-new-array-object.js

@isConstructor just checks that the ConstructData is not None. However, host functions return ConstructType::Host even if their default behavior is to throw an exception that it should not be used as a constructor. We could return ConstructType::None for these default cases.
Comment 1 Joseph Pecoraro 2016-10-14 02:04:10 PDT
Created attachment 291596 [details]
[PATCH] Proposed Fix
Comment 2 Joseph Pecoraro 2016-10-14 02:14:42 PDT
Created attachment 291599 [details]
[PATCH] Proposed Fix

Some additional test cases.
Comment 3 Saam Barati 2016-10-14 07:48:26 PDT
Comment on attachment 291599 [details]
[PATCH] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=291599&action=review

r=me

> JSTests/stress/is-constructor.js:6
> +let isConstructor = createBuiltin("(function(c) { return @isConstructor(c); })");

This is a nice test.
Comment 4 Saam Barati 2016-10-14 07:51:07 PDT
Comment on attachment 291599 [details]
[PATCH] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=291599&action=review

r=me

>> JSTests/stress/is-constructor.js:6
>> +let isConstructor = createBuiltin("(function(c) { return @isConstructor(c); })");
> 
> This is a nice test.

This is a nice test.

> Source/JavaScriptCore/runtime/JSFunction.cpp:576
> +        if (thisObject->nativeConstructor() == callHostFunctionAsConstructor)

Do we get a new kind of error message when we try to "new" non constructor host functions?
Comment 5 Joseph Pecoraro 2016-10-14 10:53:47 PDT
Comment on attachment 291599 [details]
[PATCH] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=291599&action=review

>> Source/JavaScriptCore/runtime/JSFunction.cpp:576
>> +        if (thisObject->nativeConstructor() == callHostFunctionAsConstructor)
> 
> Do we get a new kind of error message when we try to "new" non constructor host functions?

Nope, `new Math.cos` produces the exact same error message!
Comment 6 WebKit Commit Bot 2016-10-14 11:16:42 PDT
Comment on attachment 291599 [details]
[PATCH] Proposed Fix

Clearing flags on attachment: 291599

Committed r207347: <http://trac.webkit.org/changeset/207347>
Comment 7 WebKit Commit Bot 2016-10-14 11:16:45 PDT
All reviewed patches have been landed.  Closing bug.