Title: [201628] trunk/Source/_javascript_Core
- Revision
- 201628
- Author
- [email protected]
- Date
- 2016-06-02 16:52:03 -0700 (Thu, 02 Jun 2016)
Log Message
global lexical environment variables are not accessible through functions created using the function constructor
https://bugs.webkit.org/show_bug.cgi?id=158319
Reviewed by Filip Pizlo.
When creating a function using the Function constructor, we were
using the global object instead of the global lexical environment
as the function's scope. We should be using the global lexical environment.
* runtime/FunctionConstructor.cpp:
(JSC::constructFunctionSkippingEvalEnabledCheck):
* tests/stress/function-constructor-reading-from-global-lexical-environment.js: Added.
(assert):
(test):
(ClassTDZ):
Modified Paths
Added Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (201627 => 201628)
--- trunk/Source/_javascript_Core/ChangeLog 2016-06-02 23:45:31 UTC (rev 201627)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-06-02 23:52:03 UTC (rev 201628)
@@ -1,3 +1,21 @@
+2016-06-02 Saam Barati <[email protected]>
+
+ global lexical environment variables are not accessible through functions created using the function constructor
+ https://bugs.webkit.org/show_bug.cgi?id=158319
+
+ Reviewed by Filip Pizlo.
+
+ When creating a function using the Function constructor, we were
+ using the global object instead of the global lexical environment
+ as the function's scope. We should be using the global lexical environment.
+
+ * runtime/FunctionConstructor.cpp:
+ (JSC::constructFunctionSkippingEvalEnabledCheck):
+ * tests/stress/function-constructor-reading-from-global-lexical-environment.js: Added.
+ (assert):
+ (test):
+ (ClassTDZ):
+
2016-06-02 Oliver Hunt <[email protected]>
JS parser incorrectly handles invalid utf8 in error messages.
Modified: trunk/Source/_javascript_Core/runtime/FunctionConstructor.cpp (201627 => 201628)
--- trunk/Source/_javascript_Core/runtime/FunctionConstructor.cpp 2016-06-02 23:45:31 UTC (rev 201627)
+++ trunk/Source/_javascript_Core/runtime/FunctionConstructor.cpp 2016-06-02 23:52:03 UTC (rev 201628)
@@ -128,7 +128,7 @@
if (exec->hadException())
return nullptr;
- return JSFunction::create(exec->vm(), function, globalObject, subclassStructure);
+ return JSFunction::create(exec->vm(), function, globalObject->globalScope(), subclassStructure);
}
// ECMA 15.3.2 The Function Constructor
Added: trunk/Source/_javascript_Core/tests/stress/function-constructor-reading-from-global-lexical-environment.js (0 => 201628)
--- trunk/Source/_javascript_Core/tests/stress/function-constructor-reading-from-global-lexical-environment.js (rev 0)
+++ trunk/Source/_javascript_Core/tests/stress/function-constructor-reading-from-global-lexical-environment.js 2016-06-02 23:52:03 UTC (rev 201628)
@@ -0,0 +1,133 @@
+function assert(b, m) {
+ if (!b)
+ throw new Error(m);
+}
+
+function test(f, iters = 1000) {
+ noInline(f);
+ for (let i = 0; i < iters; i++)
+ f(i);
+}
+
+const globalConst = {};
+class GlobalClass { }
+let globalLet = {};
+let f = new Function("", "return globalConst;");
+test(function() {
+ assert(f() === globalConst);
+});
+
+f = new Function("", "return GlobalClass;");
+test(function() {
+ let ctor = f();
+ assert(ctor === GlobalClass);
+ assert((new GlobalClass) instanceof GlobalClass);
+});
+
+
+f = new Function("", "return globalLet;");
+test(function() {
+ assert(f() === globalLet);
+});
+
+f = new Function("prop", "x", "globalLet[prop] = x;");
+test(function(i) {
+ f(i, i);
+ assert(globalLet[i] === i);
+});
+
+f = new Function("prop", "x", "globalConst[prop] = x;");
+test(function(i) {
+ f(i, i);
+ assert(globalConst[i] === i);
+});
+
+f = new Function("", "globalConst = 25");
+test(function() {
+ let threw = false;
+ try {
+ f();
+ } catch(e) {
+ threw = true;
+ assert(e.toString() === "TypeError: Attempted to assign to readonly property.")
+ }
+ assert(threw);
+});
+
+f = new Function("", "globalConst = 25");
+test(function() {
+ let threw = false;
+ try {
+ f();
+ } catch(e) {
+ threw = true;
+ assert(e.toString() === "TypeError: Attempted to assign to readonly property.")
+ }
+ assert(threw);
+});
+
+f = new Function("", "constTDZ = 25");
+test(function() {
+ let threw = false;
+ try {
+ f();
+ } catch(e) {
+ threw = true;
+ assert(e.toString() === "ReferenceError: Cannot access uninitialized variable.")
+ }
+ assert(threw);
+});
+
+f = new Function("", "constTDZ;");
+test(function() {
+ let threw = false;
+ try {
+ f();
+ } catch(e) {
+ threw = true;
+ assert(e.toString() === "ReferenceError: Cannot access uninitialized variable.")
+ }
+ assert(threw);
+});
+
+f = new Function("", "letTDZ;");
+test(function() {
+ let threw = false;
+ try {
+ f();
+ } catch(e) {
+ threw = true;
+ assert(e.toString() === "ReferenceError: Cannot access uninitialized variable.")
+ }
+ assert(threw);
+});
+
+f = new Function("", "letTDZ = 20;");
+test(function() {
+ let threw = false;
+ try {
+ f();
+ } catch(e) {
+ threw = true;
+ assert(e.toString() === "ReferenceError: Cannot access uninitialized variable.")
+ }
+ assert(threw);
+});
+
+f = new Function("", "ClassTDZ");
+test(function() {
+ let threw = false;
+ try {
+ f();
+ } catch(e) {
+ threw = true;
+ assert(e.toString() === "ReferenceError: Cannot access uninitialized variable.")
+ }
+ assert(threw);
+});
+
+
+const constTDZ = 25;
+let letTDZ = 25;
+class ClassTDZ { }
+
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes