Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Unified Diff: test/mjsunit/harmony/object-literals-method.js

Issue 477263002: ES6: Add support for method shorthand in object literals (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/mjsunit/harmony/object-literals-method.js
diff --git a/test/mjsunit/harmony/object-literals-method.js b/test/mjsunit/harmony/object-literals-method.js
new file mode 100644
index 0000000000000000000000000000000000000000..03106dc43533468173ab43c82d96dae1b394308d
--- /dev/null
+++ b/test/mjsunit/harmony/object-literals-method.js
@@ -0,0 +1,178 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --harmony-object-literals --allow-natives-syntax
+
+
+(function TestDescriptor() {
+ var object = {
+ method() {
+ return 42;
+ }
+ };
+ assertEquals(42, object.method());
+})();
+
+
+(function TestDescriptor() {
+ var object = {
+ method() {
+ return 42;
+ }
+ };
+
+ var desc = Object.getOwnPropertyDescriptor(object, 'method');
+ assertTrue(desc.enumerable);
+ assertTrue(desc.configurable);
+ assertTrue(desc.writable);
+ assertEquals('function', typeof desc.value);
+
+ assertEquals(42, desc.value());
+})();
+
+
+(function TestProto() {
+ var object = {
+ method() {
+ return 42;
+ }
+ };
+
+ assertEquals(Function.prototype, Object.getPrototypeOf(object.method));
+})();
+
+
+(function TestNotConstructable() {
+ var object = {
+ method() {
+ return 42;
+ }
+ };
+
+ assertThrows(function() {
+ new object.method;
+ });
+})();
+
+
+(function TestFunctionName() {
+ var object = {
+ method() {
+ return 42;
+ },
+ 1() {},
+ // https://code.google.com/p/v8/issues/detail?id=3507
+ // 2.0() {}
+ };
+ var f = object.method;
+ assertEquals('method', f.name);
+ var g = object[1];
+ assertEquals('1', g.name);
+
+ // https://code.google.com/p/v8/issues/detail?id=3507
+ // var h = object[2];
+ // assertEquals('2', h.name);
+})();
+
+
+(function TestNoBinding() {
+ var method = 'local';
+ var calls = 0;
+ var object = {
+ method() {
+ calls++;
+ assertEquals('local', method);
+ }
+ };
+ object.method();
+ assertEquals(1, calls);
+})();
+
+
+(function TestNoPrototype() {
+ var object = {
+ method() {
+ return 42;
+ }
+ };
+ var f = object.method;
+ assertFalse(f.hasOwnProperty('prototype'));
+ assertEquals(undefined, f.prototype);
+
+ f.prototype = 42;
+ assertEquals(42, f.prototype);
+})();
+
+
+(function TestKeywordAsName() {
+ var keywords = [
+ 'await',
+ 'break',
+ 'case',
+ 'catch',
+ 'class',
+ 'const',
+ 'continue',
+ 'debugger',
+ 'default',
+ 'delete',
+ 'do',
+ 'else',
+ 'enum',
+ 'export',
+ 'extends',
+ 'finally',
+ 'for',
+ 'function',
+ 'if',
+ 'implements',
+ 'import',
+ 'in',
+ 'instanceof',
+ 'interface',
+ 'new',
+ 'package',
+ 'private',
+ 'protected',
+ 'public',
+ 'return',
+ 'static',
+ 'super',
+ 'switch',
+ 'this',
+ 'throw',
+ 'try',
+ 'typeof',
+ 'var',
+ 'void',
+ 'while',
+ 'with',
+ 'yield',
+ ];
+
+ for (var kw of keywords) {
+ assertEquals(kw,
+ eval('({' + kw + '() { return "' + kw + '"; }}).' + kw + '()'));
+ }
+})();
+
+
+(function TestToString() {
+ var object = {
+ method() { 42; }
+ };
+ assertEquals('method() { 42; }', object.method.toString());
+})();
+
+
+(function TestOptimized() {
+ var object = {
+ method() { return 42; }
+ };
+ assertEquals(42, object.method());
+ assertEquals(42, object.method());
+ %OptimizeFunctionOnNextCall(object.method);
+ assertEquals(42, object.method());
+ assertFalse(object.method.hasOwnProperty('prototype'));
+})();

Powered by Google App Engine
This is Rietveld 408576698