Debian Codegraph @

js/src/tests/test262/language/statements/class/definition/methods.js

raw
1 // Copyright (C) 2014 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 es6id: 14.5
5 description: >
6 class methods
7 ---*/
8 function assertMethodDescriptor(object, name) {
9 var desc = Object.getOwnPropertyDescriptor(object, name);
10 assert.sameValue(desc.configurable, true, "The value of `desc.configurable` is `true`");
11 assert.sameValue(desc.enumerable, false, "The value of `desc.enumerable` is `false`");
12 assert.sameValue(desc.writable, true, "The value of `desc.writable` is `true`");
13 assert.sameValue(typeof desc.value, 'function', "`typeof desc.value` is `'function'`");
14 assert.sameValue('prototype' in desc.value, false, "The result of `'prototype' in desc.value` is `false`");
15 }
16
17 class C {
18 method() { return 1; }
19 static staticMethod() { return 2; }
20 method2() { return 3; }
21 static staticMethod2() { return 4; }
22 }
23
24 assertMethodDescriptor(C.prototype, 'method');
25 assertMethodDescriptor(C.prototype, 'method2');
26 assertMethodDescriptor(C, 'staticMethod');
27 assertMethodDescriptor(C, 'staticMethod2');
28
29 assert.sameValue(new C().method(), 1, "`new C().method()` returns `1`. Defined as `method() { return 1; }`");
30 assert.sameValue(C.staticMethod(), 2, "`C.staticMethod()` returns `2`. Defined as `static staticMethod() { return 2; }`");
31 assert.sameValue(new C().method2(), 3, "`new C().method2()` returns `3`. Defined as `method2() { return 3; }`");
32 assert.sameValue(C.staticMethod2(), 4, "`C.staticMethod2()` returns `4`. Defined as `static staticMethod2() { return 4; }`");
33
34 reportCompare(0, 0);