Skip to content
Permalink
Browse files
Add tests for computed method declarations with side effects
https://bugs.webkit.org/show_bug.cgi?id=148057

Reviewed by Darin Adler.

Added test cases for computed method names with side effects.

* js/class-syntax-method-names-expected.txt:
* js/script-tests/class-syntax-method-names.js:


Canonical link: https://commits.webkit.org/166807@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189229 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
rniwa committed Sep 1, 2015
1 parent 0870b64 commit 510f0d86b70923d91791e65e267aaf2db0221981
Showing 3 changed files with 32 additions and 0 deletions.
@@ -1,3 +1,15 @@
2015-09-01 Ryosuke Niwa <rniwa@webkit.org>

Add tests for computed method declarations with side effects
https://bugs.webkit.org/show_bug.cgi?id=148057

Reviewed by Darin Adler.

Added test cases for computed method names with side effects.

* js/class-syntax-method-names-expected.txt:
* js/script-tests/class-syntax-method-names.js:

2015-09-01 Brian Burg <bburg@apple.com>

Unreviewed, the previous commit had incorrect expectations.
@@ -28,6 +28,11 @@ PASS class A { [0.1]() { return 213; } }; (new A)[0.1]() is 213
PASS class A { [1]() { return 214; } }; (new A)[1]() is 214
PASS A = createClassWithInstanceMethod('foo', 215); (new A)['foo']() is 215
PASS A = createClassWithInstanceMethod('foo', 216); B = createClassWithInstanceMethod('bar', 217); [(new A)['foo'](), (new B)['bar']()] is [216, 217]
PASS x = 218; class A { [x++]() { return x; } }; (new A)[218]() is 219
PASS x = undefined; class A { [(x=220) && 'foo']() { return x; } }; (new A).foo() is 220
PASS x = 221; class A { [(x1=x) && x++]() { return x1; } [(x2=x) && x++]() { return x2; } }; [(new A)[221](), (new A)[222]()] is [221, 222]
PASS x = 1; class A { ['foo' + x++]() { return 223; } ['foo' + x++]() { return 224; } }; [(new A).foo1(), (new A).foo2()] is [223, 224]
PASS x = 1; class A { ['foo' + ++x]() { return 225; } [(x1=x) && 'foo' + x++]() { return 226; } }; [x1, x, (new A).foo2()] is [2, 3, 226]

Static methods with computed names
PASS class A { static ['a' + 'b']() { return 311; } }; A.ab() is 311
@@ -36,6 +41,11 @@ PASS class A { static [0.1]() { return 313; } }; A[0.1]() is 313
PASS class A { static [1]() { return 314; } }; A[1]() is 314
PASS A = createClassWithStaticMethod('foo', 315); A['foo']() is 315
PASS A = createClassWithStaticMethod('foo', 316); B = createClassWithStaticMethod('bar', 317); [A['foo'](), B['bar']()] is [316, 317]
PASS x = 218; class A { static [x++]() { return x; } }; A[218]() is 219
PASS x = undefined; class A { static [(x=220) && 'foo']() { return x; } }; A.foo() is 220
PASS x = 221; class A { static [(x1=x) && x++]() { return x1; } static [(x2=x) && x++]() { return x2; } }; [A[221](), A[222]()] is [221, 222]
PASS x = 1; class A { static ['foo' + x++]() { return 223; } static ['foo' + x++]() { return 224; } }; [A.foo1(), A.foo2()] is [223, 224]
PASS x = 1; class A { static ['foo' + ++x]() { return 225; } static [(x1=x) && 'foo' + x++]() { return 226; } }; [x1, x, A.foo2()] is [2, 3, 226]

Instance methods with duplicated names
PASS class A { ab() { return 401 } ab() { return 402; } }; (new A).ab() is 402
@@ -28,6 +28,11 @@ shouldBe("class A { [1]() { return 214; } }; (new A)[1]()", "214");
function createClassWithInstanceMethod(name, value) { return class { [name]() { return value; } } };
shouldBe("A = createClassWithInstanceMethod('foo', 215); (new A)['foo']()", "215");
shouldBe("A = createClassWithInstanceMethod('foo', 216); B = createClassWithInstanceMethod('bar', 217); [(new A)['foo'](), (new B)['bar']()]", "[216, 217]");
shouldBe("x = 218; class A { [x++]() { return x; } }; (new A)[218]()", "219");
shouldBe("x = undefined; class A { [(x=220) && 'foo']() { return x; } }; (new A).foo()", "220");
shouldBe("x = 221; class A { [(x1=x) && x++]() { return x1; } [(x2=x) && x++]() { return x2; } }; [(new A)[221](), (new A)[222]()]", "[221, 222]");
shouldBe("x = 1; class A { ['foo' + x++]() { return 223; } ['foo' + x++]() { return 224; } }; [(new A).foo1(), (new A).foo2()]", "[223, 224]");
shouldBe("x = 1; class A { ['foo' + ++x]() { return 225; } [(x1=x) && 'foo' + x++]() { return 226; } }; [x1, x, (new A).foo2()]", "[2, 3, 226]");

debug('');
debug('Static methods with computed names');
@@ -38,6 +43,11 @@ shouldBe("class A { static [1]() { return 314; } }; A[1]()", "314");
function createClassWithStaticMethod(name, value) { return class { static [name]() { return value; } } };
shouldBe("A = createClassWithStaticMethod('foo', 315); A['foo']()", "315");
shouldBe("A = createClassWithStaticMethod('foo', 316); B = createClassWithStaticMethod('bar', 317); [A['foo'](), B['bar']()]", "[316, 317]");
shouldBe("x = 218; class A { static [x++]() { return x; } }; A[218]()", "219");
shouldBe("x = undefined; class A { static [(x=220) && 'foo']() { return x; } }; A.foo()", "220");
shouldBe("x = 221; class A { static [(x1=x) && x++]() { return x1; } static [(x2=x) && x++]() { return x2; } }; [A[221](), A[222]()]", "[221, 222]");
shouldBe("x = 1; class A { static ['foo' + x++]() { return 223; } static ['foo' + x++]() { return 224; } }; [A.foo1(), A.foo2()]", "[223, 224]");
shouldBe("x = 1; class A { static ['foo' + ++x]() { return 225; } static [(x1=x) && 'foo' + x++]() { return 226; } }; [x1, x, A.foo2()]", "[2, 3, 226]");

debug('');
debug('Instance methods with duplicated names');

0 comments on commit 510f0d8

Please sign in to comment.