forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1642476 - Make deleting a private field an error r=jorendorff
Differential Revision: https://phabricator.services.mozilla.com/D77931
- Loading branch information
Showing
6 changed files
with
129 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// |reftest| skip-if(!xulRuntime.shell) shell-option(--enable-private-fields) | ||
|
||
class A { | ||
#x = {a: 1}; | ||
b = null; | ||
es(s) { | ||
eval(s); | ||
} | ||
} | ||
|
||
var a = new A; | ||
a.b = new A; | ||
|
||
assertThrowsInstanceOf(() => a.es('delete this.#x'), SyntaxError); | ||
assertThrowsInstanceOf(() => a.es('delete (this.#x)'), SyntaxError); | ||
assertThrowsInstanceOf(() => a.es('delete this?.#x'), SyntaxError); | ||
assertThrowsInstanceOf(() => a.es('delete this?.b.#x'), SyntaxError); | ||
// Should be OK | ||
a.es('delete (0, this.#x.a)') | ||
a.es('delete this?.b.#x.a') | ||
|
||
|
||
// Make sure the above works in a different context, with emphasis on | ||
// lazy/syntax parsing. | ||
function eval_and_report(str) { | ||
var classTest = ` | ||
class B { | ||
#x = {a: 1}; | ||
b = null; | ||
test() { | ||
${str}; | ||
} | ||
} | ||
var b = new B; | ||
b.b = new B; | ||
b.test(); | ||
`; | ||
|
||
var str = ` | ||
function f(run) { | ||
if (run) { | ||
${classTest} | ||
} | ||
} | ||
f(run)`; | ||
|
||
|
||
var throws = []; | ||
// Evalutate in a new global; has the advantage that it makes successes | ||
// idempotent. | ||
var g = newGlobal(); | ||
g.run = false; | ||
|
||
try { | ||
// The idea is that this is a full parse | ||
evaluate(classTest, {global: g}); | ||
} catch (e) { | ||
throws.push(e); | ||
} | ||
|
||
try { | ||
// The idea is this is a lazy parse; however, fields currently | ||
// disable lazy parsing, so right now | ||
evaluate(str, {global: g}); | ||
} catch (e) { | ||
throws.push(e); | ||
} | ||
|
||
return throws; | ||
} | ||
|
||
function assertSyntaxError(str) { | ||
var exceptions = eval_and_report(str); | ||
assertEq(exceptions.length, 2); | ||
for (var e of exceptions) { | ||
assertEq(/SyntaxError/.test(e.name), true); | ||
} | ||
} | ||
|
||
function assertNoSyntaxError(str) { | ||
var exceptions = eval_and_report(str); | ||
assertEq(exceptions.length, 0); | ||
} | ||
|
||
assertSyntaxError('delete this.#x'); | ||
assertSyntaxError('delete (this.#x)'); | ||
assertSyntaxError('delete this?.#x'); | ||
assertSyntaxError('delete this?.b.#x'); | ||
// Should be OK | ||
assertNoSyntaxError('delete (0, this.#x.a)') | ||
assertNoSyntaxError('delete this?.b.#x.a') | ||
|
||
|
||
if (typeof reportCompare === 'function') reportCompare(0, 0); |