Bug 202485 - typeof (function that masquerades as undefined) is "function", should be "undefined"
Summary: typeof (function that masquerades as undefined) is "function", should be "und...
Status: RESOLVED DUPLICATE of bug 215572
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-02 11:17 PDT by Geoffrey Garen
Modified: 2020-12-03 09:46 PST (History)
6 users (show)

See Also:


Attachments
test case (313 bytes, text/html)
2019-10-02 11:19 PDT, Geoffrey Garen
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Geoffrey Garen 2019-10-02 11:17:40 PDT
See https://bugs.webkit.org/show_bug.cgi?id=198805.

The openDatabase function is allocated by calling JSFunction::createFunctionThatMasqueradesAsUndefined.
Comment 1 Geoffrey Garen 2019-10-02 11:19:35 PDT
Created attachment 380040 [details]
test case
Comment 2 Alexey Proskuryakov 2019-10-04 17:07:39 PDT
The test case produces PASS for me in Safari 13.0.1.

PASS: typeof window.openDatabase is undefined
Comment 3 Oz 2019-10-11 01:47:31 PDT
I believe the issue is that (were these both tests)

PASS: typeof window.openDatabase is undefined
PASS: typeof window.openDatabase is function

Both can't be true.

Specifically

window.openDatabase == "function" is true
window.openDatabase == "undefined" is also true

http://locutus.sorcerer.co.uk/demo/safari-openDatabase.html
Comment 4 Alexey Shvayka 2020-12-03 09:46:19 PST
(In reply to Oz from comment #3)
> PASS: typeof window.openDatabase is undefined
> PASS: typeof window.openDatabase is function
> 
> Both can't be true.

Nicely noted, thank you.

That discrepancy was made possible due to peephole optimization in BytecodeGenerator::emitEqualityOpImpl(), which detects patterns like `typeof X === "Y"` and emits different bytecodes depending on Y.
r265907 fixed the `typeof X === "function"` bytecode op to return `false` for masquerader (aka [[IsHTMLDDA]]) objects.

test262 coverage was added in https://github.com/tc39/test262/pull/2706.

*** This bug has been marked as a duplicate of bug 215572 ***