Skip to content

Commit

Permalink
Unreviewed, reverting 265614@main.
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=259073

Leads to a crash if there is are multiple hoisted functions by the same name <rdar://112017932>

Reverted changeset:

"[JSC] Align duplicate declaration checks in EvalDeclarationInstantiation with the spec"
https://bugs.webkit.org/show_bug.cgi?id=167837
https://commits.webkit.org/265614@main

Canonical link: https://commits.webkit.org/265915@main
  • Loading branch information
webkit-commit-queue authored and Mark Lam committed Jul 10, 2023
1 parent 24aaedc commit 67ceec5
Show file tree
Hide file tree
Showing 13 changed files with 404 additions and 415 deletions.
3 changes: 1 addition & 2 deletions JSTests/ChakraCore/test/Closures/bug_OS_2299723.baseline-jsc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
eval('var x = 5') threw 'Can't create duplicate variable in eval: 'x''
x: 5
eval('var y = 5') threw 'Can't create duplicate variable in eval: 'y''
eval('var y = 5') threw 'Attempted to assign to readonly property.'
eval('y = 5') threw 'Attempted to assign to readonly property.'
y: 1
12 changes: 6 additions & 6 deletions JSTests/stress/const-not-strict-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ function foo() {
try {
eval("var x = 20;");
} catch(e) {
threw = true;
assert(e.toString() === "SyntaxError: Can't create duplicate variable in eval: 'x'");
if (e.name.indexOf("TypeError") !== -1 && e.message.indexOf("readonly") !== -1)
threw = true;
}
assert(threw);
assert(x === 40);
}
assert(typeof x === "undefined");
assert(x === undefined);
}

function bar() {
Expand All @@ -87,13 +87,13 @@ function bar() {
try {
eval("var x = 20;");
} catch(e) {
threw = true;
assert(e.toString() === "SyntaxError: Can't create duplicate variable in eval: 'x'");
if (e.name.indexOf("TypeError") !== -1 && e.message.indexOf("readonly") !== -1)
threw = true;
}
assert(threw);
assert(x === 40);
}
assert(typeof x === "undefined");
assert(x === undefined);
}

function baz() {
Expand Down
42 changes: 0 additions & 42 deletions JSTests/stress/eval-func-decl-in-eval-within-catch-scope.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var err = new Error();
err.e = "foo";

function assert(x) {
if (!x)
Expand All @@ -26,31 +25,7 @@ function shouldThrow(func, errorMessage) {
throw err;
} catch (e) {
eval(`function e() { return 1; }`); // no error
assert(e === err);
}
assert(e() === 1);
})();

(function() {
var e = 1;
try {
throw err;
} catch (e) {
eval(`if (true) { function e() { return 1; } }`); // no error
assert(e === err);
}
assert(e() === 1);
})();

(function() {
var e = 1;
try {
throw err;
} catch ({e}) {
eval(`if (true) { function e() { return 1; } }`); // no error
assert(e === "foo");
}
assert(e === 1);
})();

shouldThrow(function() {
Expand All @@ -61,20 +36,3 @@ shouldThrow(function() {
eval(`function e() { return 1; }`); // syntax error
}
}, "SyntaxError: Can't create duplicate variable in eval: 'e'");

shouldThrow(function() {
var e = 2;
try {
throw err;
} catch ({e}) {
eval(`var e = 1;`); // syntax error
}
}, "SyntaxError: Can't create duplicate variable in eval: 'e'");

shouldThrow(function() {
try {
throw err;
} catch ({...e}) {
eval(`var e;`); // syntax error
}
}, "SyntaxError: Can't create duplicate variable in eval: 'e'");
43 changes: 0 additions & 43 deletions JSTests/stress/eval-func-decl-in-global-of-eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,46 +64,3 @@ function foobar() {
foobar();
assertThrow(() => g, "ReferenceError: Can't find variable: g");

(function() {
try {
let b;
let c;
eval('var a; var b; var c;');
} catch (e) {
var error = e;
}

assert(error.toString(), "SyntaxError: Can't create duplicate variable in eval: 'c'");
assertThrow(() => a, "ReferenceError: Can't find variable: a");
assertThrow(() => b, "ReferenceError: Can't find variable: b");
assertThrow(() => c, "ReferenceError: Can't find variable: c");
})();

(function() {
try {
let x1;
eval('function x1() {} function x2() {} function x3() {}');
} catch (e) {
var error = e;
}

assert(error.toString(), "SyntaxError: Can't create duplicate variable in eval: 'x1'");
assertThrow(() => x1, "ReferenceError: Can't find variable: x1");
assertThrow(() => x2, "ReferenceError: Can't find variable: x2");
assertThrow(() => x3, "ReferenceError: Can't find variable: x3");
})();

(function() {
var x3;
try {
let x2;
eval('function x1() {} function x2() {} function x3() {}');
} catch (e) {
var error = e;
}

assert(error.toString(), "SyntaxError: Can't create duplicate variable in eval: 'x2'");
assertThrow(() => x1, "ReferenceError: Can't find variable: x1");
assertThrow(() => x2, "ReferenceError: Can't find variable: x2");
assert(x3, undefined);
})();
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ for (var i = 0; i < 10000; i++){
assertThrow(() => _bar, "ReferenceError: Can't find variable: _bar");
}

// Fixme: https://bugs.webkit.org/show_bug.cgi?id=167837
// Current test does not work because it should raise exception
// that f could not be redeclared
/*
function goo() {
{
var error = false;
Expand All @@ -77,14 +79,13 @@ for (var i = 0; i < 10000; i++) {
goo();
assert(typeof f, "undefined", "#7");
}
*/

function hoo() {
{
let h = 20;
try { eval('var h = 15;'); } catch (e) { var evalError = e; }
assert(evalError.toString(), "SyntaxError: Can't create duplicate variable in eval: 'h'");
eval('eval("if (false) { function h() {} } ");');
assert(h, 20);
eval('var h = 15; eval(" if (false){ function h() { }; } ");');
assert(h, 15);
}
assert(typeof h, "undefined");
}
Expand Down Expand Up @@ -124,8 +125,6 @@ for (var i = 0; i < 10000; i++){

function loo() {
let h = 20;
// FIXME: This should throw SyntaxError.
// https://bugs.webkit.org/show_bug.cgi?id=258507
eval("var h; if (false) { function h() { } }");
return h;
}
Expand Down
Loading

0 comments on commit 67ceec5

Please sign in to comment.