Bug 215572

Summary: Introduce OpIsCallable bytecode and intrinsic
Product: WebKit Reporter: Alexey Shvayka <ashvayka>
Component: JavaScriptCoreAssignee: Alexey Shvayka <ashvayka>
Status: RESOLVED FIXED    
Severity: Trivial CC: ews-watchlist, ggaren, joepeck, keith_miller, mark.lam, msaboff, ross.kirsling, saam, tzagallo, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar, WebExposed
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
See Also: https://bugs.webkit.org/show_bug.cgi?id=214525
https://bugs.webkit.org/show_bug.cgi?id=214443
Attachments:
Description Flags
Patch
none
Patch none

Alexey Shvayka
Reported 2020-08-17 09:18:23 PDT
Introduce OpIsCallable bytecode and intrinsic
Attachments
Patch (69.09 KB, patch)
2020-08-17 09:25 PDT, Alexey Shvayka
no flags
Patch (73.16 KB, patch)
2020-08-19 12:51 PDT, Alexey Shvayka
no flags
Alexey Shvayka
Comment 1 2020-08-17 09:25:43 PDT
Ross Kirsling
Comment 2 2020-08-17 12:33:57 PDT
Comment on attachment 406719 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=406719&action=review Looks good from my perspective. > Source/JavaScriptCore/ChangeLog:12 > + 1. Aligns slow_path_is_function with DFG/FTL implementations by introducing > + jsTypeofIsFunction() helper. This fixes `typeof document.all === "function"` > + to return `true` instead of `false`. I think you have the operator swapped here -- should be !==, right? > Source/JavaScriptCore/runtime/Operations.h:49 > + if (object->type() == JSFunctionType) > + return true; > + if (object->structure(vm)->masqueradesAsUndefined(globalObject)) > + return false; > + if (object->isCallable(vm)) > + return true; isCallable starts by checking JSFunctionType, right? So I think we could drop the first conditional unless there's a perf implication. > LayoutTests/js/dom/script-tests/document-all-typeof-is-function-fold.js:4 > +function testTypeofIsFuction() { nit: Fuction -> Function (x2)
Saam Barati
Comment 3 2020-08-18 08:07:26 PDT
Comment on attachment 406719 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=406719&action=review LGTM too > Source/JavaScriptCore/runtime/Operations.h:47 > + return false; Your change log says the opposite
Alexey Shvayka
Comment 4 2020-08-18 08:42:37 PDT
I appreciate all the reviews! A question/suggestion: Instead of adding a new bytecode op, which I suppose should be avoided whenever possible, we could define @isCallable as a function: ``` @globalPrivate function isCallable(value) { "use strict"; return typeof value === "function" || @isCallableMasquerader(value); } ``` with @isCallableMasquerader being a link-time-constant implemented in C++. OpIsCallable is a nice primitive, yet it isn't required except by built-ins. Should I benchmark this approach?
Saam Barati
Comment 5 2020-08-18 09:57:40 PDT
(In reply to Alexey Shvayka from comment #4) > I appreciate all the reviews! A question/suggestion: > > Instead of adding a new bytecode op, which I suppose should be avoided > whenever possible, we could define @isCallable as a function: > > ``` > @globalPrivate > function isCallable(value) > { > "use strict"; > > return typeof value === "function" || @isCallableMasquerader(value); > } > ``` > > with @isCallableMasquerader being a link-time-constant implemented in C++. > OpIsCallable is a nice primitive, yet it isn't required except by built-ins. > Should I benchmark this approach? I like your current approach more
Alexey Shvayka
Comment 6 2020-08-19 12:51:31 PDT
Created attachment 406868 [details] Patch Fix typos in ChangeLog and LayoutTests, remove extra JSFunctionType check.
EWS
Comment 7 2020-08-19 16:25:50 PDT
Committed r265907: <https://trac.webkit.org/changeset/265907> All reviewed patches have been landed. Closing bug and clearing flags on attachment 406868 [details].
Radar WebKit Bug Importer
Comment 8 2020-08-19 16:26:15 PDT
Alexey Shvayka
Comment 9 2020-12-03 09:46:19 PST
*** Bug 202485 has been marked as a duplicate of this bug. ***
Note You need to log in before you can comment on or make changes to this bug.