forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add private generator method tests (tc39#1343)
- Loading branch information
1 parent
835c85c
commit 2b452c2
Showing
5 changed files
with
193 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (C) 2018 Jaideep Bhoosreddy. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
path: language/statements/class/gen-method- | ||
name: Generator private method as a ClassDeclaration element | ||
esid: prod-GeneratorPrivateMethod | ||
info: | | ||
ClassElement : | ||
PrivateMethodDefinition | ||
|
||
MethodDefinition : | ||
GeneratorMethod | ||
|
||
14.4 Generator Function Definitions | ||
|
||
GeneratorMethod : | ||
* PropertyName ( UniqueFormalParameters ) { GeneratorBody } | ||
features: [generators] | ||
---*/ | ||
|
||
var callCount = 0; | ||
|
||
class C { | ||
*#gen() { | ||
callCount += 1; | ||
/*{ body }*/ | ||
} | ||
gen() { | ||
return this.#gen(); | ||
} | ||
} | ||
|
||
const c = new C(); | ||
|
||
// Test the private fields do not appear as properties before set to value | ||
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#gen"), false, "test 1"); | ||
assert.sameValue(Object.hasOwnProperty.call(C, "#gen"), false, "test 2"); | ||
assert.sameValue(Object.hasOwnProperty.call(c, "#gen"), false, "test 3"); | ||
|
||
var iter = c.gen(); | ||
|
||
/*{ assertions }*/ | ||
|
||
assert.sameValue(callCount, 1); | ||
|
||
// Test the private fields do not appear as properties after set to value | ||
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#gen"), false, "test 1"); | ||
assert.sameValue(Object.hasOwnProperty.call(C, "#gen"), false, "test 2"); | ||
assert.sameValue(Object.hasOwnProperty.call(c, "#gen"), false, "test 3"); |
47 changes: 47 additions & 0 deletions
47
src/generators/default/class-decl-static-private-method.template
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,47 @@ | ||
// Copyright (C) 2018 Jaideep Bhoosreddy. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
path: language/statements/class/gen-private-method-static- | ||
name: Static generator private method as a ClassDeclaration element | ||
esid: prod-GeneratorPrivateMethod | ||
info: | | ||
ClassElement : | ||
static PrivateMethodDefinition | ||
|
||
MethodDefinition : | ||
GeneratorMethod | ||
|
||
14.4 Generator Function Definitions | ||
|
||
GeneratorMethod : | ||
* PropertyName ( UniqueFormalParameters ) { GeneratorBody } | ||
features: [generators] | ||
---*/ | ||
|
||
var callCount = 0; | ||
|
||
class C { | ||
static #*gen() { | ||
callCount += 1; | ||
/*{ body }*/ | ||
} | ||
static gen() { | ||
return C.gen(); | ||
} | ||
} | ||
|
||
var gen = C.gen; | ||
|
||
// Test the private fields do not appear as properties before set to value | ||
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#gen"), false, "test 1"); | ||
assert.sameValue(Object.hasOwnProperty.call(C, "#gen"), false, "test 2"); | ||
|
||
var iter = gen(); | ||
|
||
/*{ assertions }*/ | ||
|
||
assert.sameValue(callCount, 1); | ||
|
||
// Test the private fields do not appear as properties before set to value | ||
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#gen"), false, "test 1"); | ||
assert.sameValue(Object.hasOwnProperty.call(C, "#gen"), false, "test 2"); |
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,49 @@ | ||
// Copyright (C) 2018 Jaideep Bhoosreddy. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
path: language/expressions/class/gen-private-method- | ||
name: Generator private method as a ClassExpression element | ||
esid: prod-GeneratorPrivateMethod | ||
info: | | ||
ClassElement : | ||
PrivateMethodDefinition | ||
|
||
MethodDefinition : | ||
GeneratorMethod | ||
|
||
14.4 Generator Function Definitions | ||
|
||
GeneratorMethod : | ||
* PropertyName ( UniqueFormalParameters ) { GeneratorBody } | ||
features: [generators] | ||
---*/ | ||
|
||
var callCount = 0; | ||
|
||
var C = class { | ||
*gen() { | ||
callCount += 1; | ||
/*{ body }*/ | ||
} | ||
gen() { | ||
return this.#gen(); | ||
} | ||
} | ||
|
||
const c = new C(); | ||
|
||
// Test the private fields do not appear as properties before set to value | ||
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#gen"), false, "test 1"); | ||
assert.sameValue(Object.hasOwnProperty.call(C, "#gen"), false, "test 2"); | ||
assert.sameValue(Object.hasOwnProperty.call(c, "#gen"), false, "test 3"); | ||
|
||
var iter = c.gen(); | ||
|
||
/*{ assertions }*/ | ||
|
||
assert.sameValue(callCount, 1); | ||
|
||
// Test the private fields do not appear as properties after set to value | ||
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#gen"), false, "test 1"); | ||
assert.sameValue(Object.hasOwnProperty.call(C, "#gen"), false, "test 2"); | ||
assert.sameValue(Object.hasOwnProperty.call(c, "#gen"), false, "test 3"); |
47 changes: 47 additions & 0 deletions
47
src/generators/default/class-expr-static-private-method.template
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,47 @@ | ||
// Copyright (C) 2017 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
path: language/expressions/class/gen-private-method-static- | ||
name: Static generator private method as a ClassExpression element | ||
esid: prod-GeneratorPrivateMethod | ||
info: | | ||
ClassElement : | ||
static PrivateMethodDefinition | ||
|
||
MethodDefinition : | ||
GeneratorMethod | ||
|
||
14.4 Generator Function Definitions | ||
|
||
GeneratorMethod : | ||
* PropertyName ( UniqueFormalParameters ) { GeneratorBody } | ||
features: [generators] | ||
---*/ | ||
|
||
var callCount = 0; | ||
|
||
var C = class { | ||
static *gen() { | ||
callCount += 1; | ||
/*{ body }*/ | ||
} | ||
static gen() { | ||
return C.gen(); | ||
} | ||
} | ||
|
||
var gen = C.gen; | ||
|
||
// Test the private fields do not appear as properties before set to value | ||
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#gen"), false, "test 1"); | ||
assert.sameValue(Object.hasOwnProperty.call(C, "#gen"), false, "test 2"); | ||
|
||
var iter = gen(); | ||
|
||
/*{ assertions }*/ | ||
|
||
assert.sameValue(callCount, 1); | ||
|
||
// Test the private fields do not appear as properties before set to value | ||
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#gen"), false, "test 1"); | ||
assert.sameValue(Object.hasOwnProperty.call(C, "#gen"), false, "test 2"); |