WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
156676
[ES6] Use @isObject to check Object Type instead of using instanceof
https://bugs.webkit.org/show_bug.cgi?id=156676
Summary
[ES6] Use @isObject to check Object Type instead of using instanceof
Yusuke Suzuki
Reported
2016-04-17 08:54:14 PDT
[ES6] Use @isObject to check Object Type instead of using instanceof
Attachments
Patch
(5.31 KB, patch)
2016-04-17 09:07 PDT
,
Yusuke Suzuki
darin
: review+
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
Yusuke Suzuki
Comment 1
2016-04-17 09:07:09 PDT
Created
attachment 276591
[details]
Patch
Yusuke Suzuki
Comment 2
2016-04-17 09:10:29 PDT
BTW, this is why Array.isArray is introduced despite there is `instanceof Array`.
Darin Adler
Comment 3
2016-04-17 09:33:25 PDT
Comment on
attachment 276591
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=276591&action=review
I noticed other similar usage of instanceof elsewhere. For example, "instanceof @Number" in toLocaleString. Does that have a similar problem. In WebCore I see "instanceof @Array" in one part, "instanceof Array" in another part, and "instanceof Function" . Do any of those have similar problems? When is it appropriate to use "Array" instead of "@Array"? I would like to understand more about correct ways to write JavaScript implementations both in the JavaScript engine and the DOM implementation.
> Source/JavaScriptCore/jsc.cpp:1783 > + return JSValue::encode(GlobalObject::create(exec->vm(), GlobalObject::createStructure(exec->vm(), jsNull()), Vector<String>()));
Since exec->vm() does a number of memory accesses, I often wonder whether we should put it in a local variable in cases like this. Not important in the JSC tool I suppose, but important as an idiom elsewhere in WebKit.
Yusuke Suzuki
Comment 4
2016-04-17 14:47:24 PDT
(In reply to
comment #3
)
> Comment on
attachment 276591
[details]
> Patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=276591&action=review
> > I noticed other similar usage of instanceof elsewhere. For example, > "instanceof @Number" in toLocaleString. Does that have a similar problem.
Yup. That's wrong and they also should be fixed. For `instanceof @Number` case, we should add @thisNumberValue abstract operation, similar to @thisTimeValue for Date. I've opened the issue for that.
https://bugs.webkit.org/show_bug.cgi?id=156680
> In WebCore I see "instanceof @Array" in one part, "instanceof Array" in > another part, and "instanceof Function" . Do any of those have similar > problems? When is it appropriate to use "Array" instead of "@Array"? I would > like to understand more about correct ways to write JavaScript > implementations both in the JavaScript engine and the DOM implementation.
I think `instanceof @Array` in fetch/FetchHeader.js is a problem. Since it is internal builtin JS, we should take care such edge cases. But I'm not sure mediacontrols should consider these cases. Mediacontrols are used to construct media UI, and it seems that the code is written as usual user-level JS code; it does not use builtins and it directly uses usual APIs (It means that user can replace the called APIs). And for the WebRTC's addIceCandidate() case, I think `candidate instanceof @RTCIceCandidate` is ok; this is because addIceCandidate() does not have any step-by-step spec. The rough implementation for now seems acceptable.
> > > Source/JavaScriptCore/jsc.cpp:1783 > > + return JSValue::encode(GlobalObject::create(exec->vm(), GlobalObject::createStructure(exec->vm(), jsNull()), Vector<String>())); > > Since exec->vm() does a number of memory accesses, I often wonder whether we > should put it in a local variable in cases like this. Not important in the > JSC tool I suppose, but important as an idiom elsewhere in WebKit.
Thanks, fixed.
Yusuke Suzuki
Comment 5
2016-04-17 14:53:14 PDT
Committed
r199647
: <
http://trac.webkit.org/changeset/199647
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug