[Webkit-unassigned] [Bug 201695] New: Function declaration statements in false conditional contexts create working functions and assign them to identifiers in the parent context.
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Wed Sep 11 13:33:59 PDT 2019
https://bugs.webkit.org/show_bug.cgi?id=201695
Bug ID: 201695
Summary: Function declaration statements in false conditional
contexts create working functions and assign them to
identifiers in the parent context.
Product: WebKit
Version: Safari 12
Hardware: Unspecified
OS: Unspecified
Status: NEW
Severity: Normal
Priority: P2
Component: JavaScriptCore
Assignee: webkit-unassigned at lists.webkit.org
Reporter: dlivesay at mac.com
The following statement
if (false) {
function myFunction(){
return "I work!";
}
}
should declare a variable, "myFunction," in the parent namespace, if it doesn't already exist, but it should neither assign a value to the variable nor create a function. This behavior is confirmed, for example, in the Google Chrome console:
> if(false){function myFunction(){return "I work!";}}
< undefined
> "myFunction" in window
< true
> typeof myFunction
< "undefined"
And attempting to invoke myFunction throws a TypeError error.
In the Safari console, however, a working function is created and assigned to the variable:
> if(false){function myFunction(){return "I work!";}}
< undefined
> "myFunction" in window
< true
> typeof myFunction
< "function"
> myFunction()
< "I work!"
The behavior is the same if the variable already exists and has a value in the parent namespace:
> myFunction = "just a string"
< "just a string"
> typeof myFunction
< "string"
> if(false){function myFunction(){return "I work!";}}
< undefined
> typeof myFunction
< "function"
Thus, the existing value is overwritten with the function.
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20190911/7be381a9/attachment.html>
More information about the webkit-unassigned
mailing list