EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_modules)
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_arrays)
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_array_includes)
-EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_classes)
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_regexps)
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_arrow_functions)
EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_tostring)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_modules)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_arrays)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_array_includes)
-EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_classes)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_arrow_functions)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_proxies)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy)
static const char* harmony_array_includes_natives[] = {
"native harmony-array-includes.js", nullptr};
static const char* harmony_proxies_natives[] = {"native proxy.js", nullptr};
- static const char* harmony_classes_natives[] = {nullptr};
static const char* harmony_modules_natives[] = {nullptr};
static const char* harmony_regexps_natives[] = {"native harmony-regexp.js",
nullptr};
#define HARMONY_SHIPPING(V) \
V(harmony_arrays, "harmony array methods") \
V(harmony_arrow_functions, "harmony arrow functions") \
- V(harmony_classes, "harmony classes") \
V(harmony_computed_property_names, "harmony computed property names") \
V(harmony_spreadcalls, "harmony spread-calls") \
V(harmony_spread_arrays, "harmony spread in array literals") \
set_allow_natives(FLAG_allow_natives_syntax || info->is_native());
set_allow_harmony_modules(!info->is_native() && FLAG_harmony_modules);
set_allow_harmony_arrow_functions(FLAG_harmony_arrow_functions);
- set_allow_harmony_classes(FLAG_harmony_classes);
set_allow_harmony_sloppy(FLAG_harmony_sloppy);
set_allow_harmony_unicode(FLAG_harmony_unicode);
set_allow_harmony_computed_property_names(
SET_ALLOW(natives);
SET_ALLOW(harmony_modules);
SET_ALLOW(harmony_arrow_functions);
- SET_ALLOW(harmony_classes);
SET_ALLOW(harmony_sloppy);
SET_ALLOW(harmony_unicode);
SET_ALLOW(harmony_computed_property_names);
#undef ALLOW_ACCESSORS
bool allow_harmony_modules() const { return scanner()->HarmonyModules(); }
- bool allow_harmony_classes() const { return scanner()->HarmonyClasses(); }
bool allow_harmony_unicode() const { return scanner()->HarmonyUnicode(); }
void set_allow_harmony_modules(bool a) { scanner()->SetHarmonyModules(a); }
- void set_allow_harmony_classes(bool a) { scanner()->SetHarmonyClasses(a); }
void set_allow_harmony_unicode(bool a) { scanner()->SetHarmonyUnicode(a); }
protected:
bookmark_c0_(kNoBookmark),
octal_pos_(Location::invalid()),
harmony_modules_(false),
- harmony_classes_(false),
harmony_unicode_(false) {
bookmark_current_.literal_chars = &bookmark_current_literal_;
bookmark_current_.raw_literal_chars = &bookmark_current_raw_literal_;
// ----------------------------------------------------------------------------
// Keyword Matcher
-#define KEYWORDS(KEYWORD_GROUP, KEYWORD) \
- KEYWORD_GROUP('b') \
- KEYWORD("break", Token::BREAK) \
- KEYWORD_GROUP('c') \
- KEYWORD("case", Token::CASE) \
- KEYWORD("catch", Token::CATCH) \
- KEYWORD("class", \
- harmony_classes ? Token::CLASS : Token::FUTURE_RESERVED_WORD) \
- KEYWORD("const", Token::CONST) \
- KEYWORD("continue", Token::CONTINUE) \
- KEYWORD_GROUP('d') \
- KEYWORD("debugger", Token::DEBUGGER) \
- KEYWORD("default", Token::DEFAULT) \
- KEYWORD("delete", Token::DELETE) \
- KEYWORD("do", Token::DO) \
- KEYWORD_GROUP('e') \
- KEYWORD("else", Token::ELSE) \
- KEYWORD("enum", Token::FUTURE_RESERVED_WORD) \
- KEYWORD("export", \
- harmony_modules ? Token::EXPORT : Token::FUTURE_RESERVED_WORD) \
- KEYWORD("extends", \
- harmony_classes ? Token::EXTENDS : Token::FUTURE_RESERVED_WORD) \
- KEYWORD_GROUP('f') \
- KEYWORD("false", Token::FALSE_LITERAL) \
- KEYWORD("finally", Token::FINALLY) \
- KEYWORD("for", Token::FOR) \
- KEYWORD("function", Token::FUNCTION) \
- KEYWORD_GROUP('i') \
- KEYWORD("if", Token::IF) \
- KEYWORD("implements", Token::FUTURE_STRICT_RESERVED_WORD) \
- KEYWORD("import", \
- harmony_modules ? Token::IMPORT : Token::FUTURE_RESERVED_WORD) \
- KEYWORD("in", Token::IN) \
- KEYWORD("instanceof", Token::INSTANCEOF) \
- KEYWORD("interface", Token::FUTURE_STRICT_RESERVED_WORD) \
- KEYWORD_GROUP('l') \
- KEYWORD("let", Token::LET) \
- KEYWORD_GROUP('n') \
- KEYWORD("new", Token::NEW) \
- KEYWORD("null", Token::NULL_LITERAL) \
- KEYWORD_GROUP('p') \
- KEYWORD("package", Token::FUTURE_STRICT_RESERVED_WORD) \
- KEYWORD("private", Token::FUTURE_STRICT_RESERVED_WORD) \
- KEYWORD("protected", Token::FUTURE_STRICT_RESERVED_WORD) \
- KEYWORD("public", Token::FUTURE_STRICT_RESERVED_WORD) \
- KEYWORD_GROUP('r') \
- KEYWORD("return", Token::RETURN) \
- KEYWORD_GROUP('s') \
- KEYWORD("static", harmony_classes ? Token::STATIC \
- : Token::FUTURE_STRICT_RESERVED_WORD) \
- KEYWORD("super", \
- harmony_classes ? Token::SUPER : Token::FUTURE_RESERVED_WORD) \
- KEYWORD("switch", Token::SWITCH) \
- KEYWORD_GROUP('t') \
- KEYWORD("this", Token::THIS) \
- KEYWORD("throw", Token::THROW) \
- KEYWORD("true", Token::TRUE_LITERAL) \
- KEYWORD("try", Token::TRY) \
- KEYWORD("typeof", Token::TYPEOF) \
- KEYWORD_GROUP('v') \
- KEYWORD("var", Token::VAR) \
- KEYWORD("void", Token::VOID) \
- KEYWORD_GROUP('w') \
- KEYWORD("while", Token::WHILE) \
- KEYWORD("with", Token::WITH) \
- KEYWORD_GROUP('y') \
+#define KEYWORDS(KEYWORD_GROUP, KEYWORD) \
+ KEYWORD_GROUP('b') \
+ KEYWORD("break", Token::BREAK) \
+ KEYWORD_GROUP('c') \
+ KEYWORD("case", Token::CASE) \
+ KEYWORD("catch", Token::CATCH) \
+ KEYWORD("class", Token::CLASS) \
+ KEYWORD("const", Token::CONST) \
+ KEYWORD("continue", Token::CONTINUE) \
+ KEYWORD_GROUP('d') \
+ KEYWORD("debugger", Token::DEBUGGER) \
+ KEYWORD("default", Token::DEFAULT) \
+ KEYWORD("delete", Token::DELETE) \
+ KEYWORD("do", Token::DO) \
+ KEYWORD_GROUP('e') \
+ KEYWORD("else", Token::ELSE) \
+ KEYWORD("enum", Token::FUTURE_RESERVED_WORD) \
+ KEYWORD("export", \
+ harmony_modules ? Token::EXPORT : Token::FUTURE_RESERVED_WORD) \
+ KEYWORD("extends", Token::EXTENDS) \
+ KEYWORD_GROUP('f') \
+ KEYWORD("false", Token::FALSE_LITERAL) \
+ KEYWORD("finally", Token::FINALLY) \
+ KEYWORD("for", Token::FOR) \
+ KEYWORD("function", Token::FUNCTION) \
+ KEYWORD_GROUP('i') \
+ KEYWORD("if", Token::IF) \
+ KEYWORD("implements", Token::FUTURE_STRICT_RESERVED_WORD) \
+ KEYWORD("import", \
+ harmony_modules ? Token::IMPORT : Token::FUTURE_RESERVED_WORD) \
+ KEYWORD("in", Token::IN) \
+ KEYWORD("instanceof", Token::INSTANCEOF) \
+ KEYWORD("interface", Token::FUTURE_STRICT_RESERVED_WORD) \
+ KEYWORD_GROUP('l') \
+ KEYWORD("let", Token::LET) \
+ KEYWORD_GROUP('n') \
+ KEYWORD("new", Token::NEW) \
+ KEYWORD("null", Token::NULL_LITERAL) \
+ KEYWORD_GROUP('p') \
+ KEYWORD("package", Token::FUTURE_STRICT_RESERVED_WORD) \
+ KEYWORD("private", Token::FUTURE_STRICT_RESERVED_WORD) \
+ KEYWORD("protected", Token::FUTURE_STRICT_RESERVED_WORD) \
+ KEYWORD("public", Token::FUTURE_STRICT_RESERVED_WORD) \
+ KEYWORD_GROUP('r') \
+ KEYWORD("return", Token::RETURN) \
+ KEYWORD_GROUP('s') \
+ KEYWORD("static", Token::STATIC) \
+ KEYWORD("super", Token::SUPER) \
+ KEYWORD("switch", Token::SWITCH) \
+ KEYWORD_GROUP('t') \
+ KEYWORD("this", Token::THIS) \
+ KEYWORD("throw", Token::THROW) \
+ KEYWORD("true", Token::TRUE_LITERAL) \
+ KEYWORD("try", Token::TRY) \
+ KEYWORD("typeof", Token::TYPEOF) \
+ KEYWORD_GROUP('v') \
+ KEYWORD("var", Token::VAR) \
+ KEYWORD("void", Token::VOID) \
+ KEYWORD_GROUP('w') \
+ KEYWORD("while", Token::WHILE) \
+ KEYWORD("with", Token::WITH) \
+ KEYWORD_GROUP('y') \
KEYWORD("yield", Token::YIELD)
static Token::Value KeywordOrIdentifierToken(const uint8_t* input,
int input_length,
- bool harmony_modules,
- bool harmony_classes) {
+ bool harmony_modules) {
DCHECK(input_length >= 1);
const int kMinLength = 2;
const int kMaxLength = 10;
}
return Token::FUTURE_STRICT_RESERVED_WORD ==
KeywordOrIdentifierToken(string->raw_data(), string->length(),
- harmony_modules_, harmony_classes_);
+ harmony_modules_);
}
literal.Complete();
Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal();
return KeywordOrIdentifierToken(chars.start(), chars.length(),
- harmony_modules_, harmony_classes_);
+ harmony_modules_);
}
HandleLeadSurrogate();
if (next_.literal_chars->is_one_byte()) {
Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal();
- return KeywordOrIdentifierToken(chars.start(),
- chars.length(),
- harmony_modules_,
- harmony_classes_);
+ return KeywordOrIdentifierToken(chars.start(), chars.length(),
+ harmony_modules_);
}
return Token::IDENTIFIER;
}
void SetHarmonyModules(bool modules) {
harmony_modules_ = modules;
}
- bool HarmonyClasses() const {
- return harmony_classes_;
- }
- void SetHarmonyClasses(bool classes) {
- harmony_classes_ = classes;
- }
+
bool HarmonyUnicode() const { return harmony_unicode_; }
void SetHarmonyUnicode(bool unicode) { harmony_unicode_ = unicode; }
bool has_multiline_comment_before_next_;
// Whether we scan 'module', 'import', 'export' as keywords.
bool harmony_modules_;
- // Whether we scan 'class', 'extends', 'static' and 'super' as keywords.
- bool harmony_classes_;
// Whether we allow \u{xxxxx}.
bool harmony_unicode_;
};
TEST(ClassLiteral) {
- FLAG_harmony_classes = true;
FLAG_harmony_sloppy = true;
const char* src =
"(function(a,b) {"
TEST(SuperAccessControl) {
i::FLAG_allow_natives_syntax = true;
- i::FLAG_harmony_classes = true;
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handle_scope(isolate);
v8::Handle<v8::ObjectTemplate> obj_template =
TEST(Regress470113) {
- i::FLAG_harmony_classes = true;
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handle_scope(isolate);
v8::Handle<v8::ObjectTemplate> obj_template =
TEST(ClassPrototypeCreationContext) {
- i::FLAG_harmony_classes = true;
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handle_scope(isolate);
LocalContext env;
i::Scanner scanner(&unicode_cache);
// The scanner should parse Harmony keywords for this test.
scanner.SetHarmonyModules(true);
- scanner.SetHarmonyClasses(true);
scanner.Initialize(&stream);
CHECK_EQ(key_token.token, scanner.Next());
CHECK_EQ(i::Token::EOS, scanner.Next());
i::ParseInfo info(&zone, script);
i::Parser parser(&info);
parser.set_allow_harmony_arrow_functions(true);
- parser.set_allow_harmony_classes(true);
parser.set_allow_harmony_sloppy(true);
info.set_global();
CHECK(parser.Parse(&info));
kAllowNatives,
kAllowHarmonyModules,
kAllowHarmonyArrowFunctions,
- kAllowHarmonyClasses,
kAllowHarmonyRestParameters,
kAllowHarmonySloppy,
kAllowHarmonyUnicode,
parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules));
parser->set_allow_harmony_arrow_functions(
flags.Contains(kAllowHarmonyArrowFunctions));
- parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses));
parser->set_allow_harmony_rest_params(
flags.Contains(kAllowHarmonyRestParameters));
parser->set_allow_harmony_spreadcalls(
RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
always_flags, arraysize(always_flags));
- static const ParserFlag classes_flags[] = {kAllowHarmonyArrowFunctions,
- kAllowHarmonyClasses};
+ static const ParserFlag classes_flags[] = {kAllowHarmonyArrowFunctions};
RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
classes_flags, arraysize(classes_flags));
}
nullptr
};
- static const ParserFlag always_flags[] = {kAllowHarmonyClasses};
-
- RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
- always_flags, arraysize(always_flags));
+ RunParserSyncTest(context_data, statement_data, kSuccess);
}
static const ParserFlag always_flags[] = {
kAllowHarmonyArrowFunctions,
- kAllowHarmonyClasses,
kAllowHarmonySloppy
};
RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
NULL
};
- static const ParserFlag always_flags[] = {
- kAllowHarmonyClasses,
- kAllowHarmonySloppy
- };
+ static const ParserFlag always_flags[] = {kAllowHarmonySloppy};
RunParserSyncTest(context_data, expression_data, kError, NULL, 0,
always_flags, arraysize(always_flags));
}
NULL
};
- static const ParserFlag always_flags[] = {
- kAllowHarmonyArrowFunctions,
- kAllowHarmonyClasses,
- kAllowHarmonySloppy
- };
+ static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions,
+ kAllowHarmonySloppy};
RunParserSyncTest(context_data, success_data, kSuccess, NULL, 0,
always_flags, arraysize(always_flags));
NULL
};
- static const ParserFlag always_flags[] = {
- kAllowHarmonyArrowFunctions,
- kAllowHarmonyClasses,
- kAllowHarmonySloppy
- };
+ static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions,
+ kAllowHarmonySloppy};
RunParserSyncTest(context_data, expression_data, kSuccess, NULL, 0,
always_flags, arraysize(always_flags));
}
NULL
};
- static const ParserFlag always_flags[] = {
- kAllowHarmonyArrowFunctions,
- kAllowHarmonyClasses,
- kAllowHarmonySloppy
- };
+ static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions,
+ kAllowHarmonySloppy};
RunParserSyncTest(context_data, statement_data, kError, NULL, 0,
always_flags, arraysize(always_flags));
}
};
static const ParserFlag always_flags[] = {
- kAllowHarmonyClasses,
kAllowHarmonySloppy
};
RunParserSyncTest(context_data, statement_data, kError, NULL, 0,
"class name extends class base {} {}",
NULL};
- static const ParserFlag always_flags[] = {
- kAllowHarmonyClasses, kAllowHarmonySloppy};
+ static const ParserFlag always_flags[] = {kAllowHarmonySloppy};
RunParserSyncTest(context_data, class_data, kSuccess, NULL, 0,
always_flags, arraysize(always_flags));
}
"class name extends class base {} {}",
NULL};
- static const ParserFlag always_flags[] = {kAllowHarmonyClasses};
- RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
- always_flags, arraysize(always_flags));
+ RunParserSyncTest(context_data, statement_data, kSuccess);
}
NULL};
static const ParserFlag always_flags[] = {
- kAllowHarmonyClasses,
kAllowHarmonySloppy
};
RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0,
NULL};
static const ParserFlag always_flags[] = {
- kAllowHarmonyClasses,
kAllowHarmonySloppy
};
RunParserSyncTest(context_data, name_data, kSuccess, NULL, 0,
NULL};
static const ParserFlag always_flags[] = {
- kAllowHarmonyClasses,
kAllowHarmonySloppy
};
RunParserSyncTest(context_data, class_data, kError, NULL, 0,
NULL};
static const ParserFlag always_flags[] = {
- kAllowHarmonyClasses,
kAllowHarmonySloppy
};
RunParserSyncTest(context_data, class_data, kError, NULL, 0,
NULL};
static const ParserFlag always_flags[] = {
- kAllowHarmonyClasses,
kAllowHarmonySloppy
};
RunParserSyncTest(context_data, class_name, kError, NULL, 0,
NULL};
static const ParserFlag always_flags[] = {
- kAllowHarmonyClasses,
kAllowHarmonySloppy
};
RunParserSyncTest(context_data, class_name, kError, NULL, 0,
NULL};
static const ParserFlag always_flags[] = {
- kAllowHarmonyClasses,
kAllowHarmonySloppy
};
RunParserSyncTest(context_data, class_body_data, kError, NULL, 0,
NULL};
static const ParserFlag always_flags[] = {
- kAllowHarmonyClasses,
kAllowHarmonySloppy
};
RunParserSyncTest(context_data, class_body_data, kError, NULL, 0,
NULL};
static const ParserFlag always_flags[] = {
- kAllowHarmonyClasses,
kAllowHarmonySloppy
};
RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0,
NULL};
static const ParserFlag always_flags[] = {
- kAllowHarmonyClasses,
kAllowHarmonySloppy
};
RunParserSyncTest(context_data, class_body_data, kError, NULL, 0,
NULL};
static const ParserFlag always_flags[] = {
- kAllowHarmonyClasses,
kAllowHarmonySloppy
};
RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0,
NULL};
static const ParserFlag always_flags[] = {
- kAllowHarmonyClasses,
kAllowHarmonySloppy
};
RunParserSyncTest(context_data, class_body_data, kError, NULL, 0,
{nullptr, nullptr}};
const char* data[] = {"...a", "...arguments", "...eval", nullptr};
- static const ParserFlag always_flags[] = {
- kAllowHarmonyRestParameters, kAllowHarmonyClasses, kAllowHarmonySloppy};
+ static const ParserFlag always_flags[] = {kAllowHarmonyRestParameters,
+ kAllowHarmonySloppy};
RunParserSyncTest(context_data, data, kError, nullptr, 0, always_flags,
arraysize(always_flags));
}
"(class C {})",
"(class C extends D {})",
NULL};
- static const ParserFlag always_true_flags[] = {kAllowHarmonyClasses};
static const ParserFlag always_false_flags[] = {kAllowHarmonySloppy};
- RunParserSyncTest(context_data, bad_data, kError, NULL, 0,
- always_true_flags, arraysize(always_true_flags),
+ RunParserSyncTest(context_data, bad_data, kError, NULL, 0, NULL, 0,
always_false_flags, arraysize(always_false_flags));
const char* good_data[] = {
"let = 1;",
"for(let = 1;;){}",
NULL};
- RunParserSyncTest(context_data, good_data, kSuccess, NULL, 0,
- always_true_flags, arraysize(always_true_flags),
+ RunParserSyncTest(context_data, good_data, kSuccess, NULL, 0, NULL, 0,
always_false_flags, arraysize(always_false_flags));
}
NULL};
static const ParserFlag always_flags[] = {
- kAllowHarmonyClasses,
kAllowHarmonyComputedPropertyNames,
kAllowHarmonySloppy,
};
NULL};
static const ParserFlag always_flags[] = {
- kAllowHarmonyClasses,
kAllowHarmonyComputedPropertyNames,
kAllowHarmonySloppy,
};
i::Zone zone;
i::ParseInfo info(&zone, script);
i::Parser parser(&info);
- parser.set_allow_harmony_classes(true);
parser.set_allow_harmony_modules(true);
info.set_module();
if (!parser.Parse(&info)) {
i::Zone zone;
i::ParseInfo info(&zone, script);
i::Parser parser(&info);
- parser.set_allow_harmony_classes(true);
parser.set_allow_harmony_modules(true);
info.set_global();
CHECK(!parser.Parse(&info));
i::Zone zone;
i::ParseInfo info(&zone, script);
i::Parser parser(&info);
- parser.set_allow_harmony_classes(true);
parser.set_allow_harmony_modules(true);
info.set_module();
CHECK(!parser.Parse(&info));
"class C {}",
NULL};
- static const ParserFlag always_flags[] = {kAllowHarmonyClasses,
- kAllowStrongMode};
+ static const ParserFlag always_flags[] = {kAllowStrongMode};
RunParserSyncTest(context_data, statement_data, kError, NULL, 0,
always_flags, arraysize(always_flags));
}
NULL};
- static const ParserFlag always_flags[] = {kAllowHarmonyClasses,
- kAllowStrongMode};
+ static const ParserFlag always_flags[] = {kAllowStrongMode};
RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
always_flags, arraysize(always_flags));
}
"class C { constructor() { label: 0; this.a = 0; this.b = 6; } }",
NULL};
- static const ParserFlag always_flags[] = {
- kAllowStrongMode, kAllowHarmonyClasses, kAllowHarmonyArrowFunctions};
+ static const ParserFlag always_flags[] = {kAllowStrongMode,
+ kAllowHarmonyArrowFunctions};
RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0,
always_flags, arraysize(always_flags));
RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0,
"class C extends Object { constructor() { 3; super(3); this.x = 0; } }",
NULL};
- static const ParserFlag always_flags[] = {
- kAllowStrongMode, kAllowHarmonyClasses, kAllowHarmonyArrowFunctions};
+ static const ParserFlag always_flags[] = {kAllowStrongMode,
+ kAllowHarmonyArrowFunctions};
RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0,
always_flags, arraysize(always_flags));
RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0,
"class C extends Array { constructor() { super(); this.a = 9; return } }",
NULL};
- static const ParserFlag always_flags[] = {kAllowStrongMode,
- kAllowHarmonyClasses};
+ static const ParserFlag always_flags[] = {kAllowStrongMode};
RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0,
always_flags, arraysize(always_flags));
RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0,
static const ParserFlag always_flags[] = {
kAllowHarmonyArrowFunctions,
- kAllowHarmonyClasses,
kAllowHarmonyNewTarget,
kAllowHarmonySloppy,
};
"path": ["Classes"],
"main": "run.js",
"resources": ["super.js", "default-constructor.js"],
- "flags": ["--harmony-classes"],
"results_regexp": "^%s\\-Classes\\(Score\\): (.+)$",
"tests": [
{"name": "Super"},
// 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-classes
+
+
'use strict';
class C {
// 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-classes
+
+
'use strict';
class C {
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
-// Flags: --harmony-rest-parameters --harmony-classes
+// Flags: --harmony-rest-parameters
'use strict';
var _bad = "setting this should fail!";
// 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-classes
+
+
'use strict';
class C {
// 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-classes
+
+
'use strict';
class C {
// Copyright 2015 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-classes
+
+
'use strict';
function f() {
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Flags: --harmony-classes
-
function CheckError(source) {
var exception = null;
try {
--- /dev/null
+// Copyright 2015 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-sloppy
+
+
+(function Method() {
+ class C {
+ eval() {
+ return 1;
+ }
+ arguments() {
+ return 2;
+ }
+ static eval() {
+ return 3;
+ }
+ static arguments() {
+ return 4;
+ }
+ };
+
+ assertEquals(1, new C().eval());
+ assertEquals(2, new C().arguments());
+ assertEquals(3, C.eval());
+ assertEquals(4, C.arguments());
+})();
+
+
+(function Getters() {
+ class C {
+ get eval() {
+ return 1;
+ }
+ get arguments() {
+ return 2;
+ }
+ static get eval() {
+ return 3;
+ }
+ static get arguments() {
+ return 4;
+ }
+ };
+
+ assertEquals(1, new C().eval);
+ assertEquals(2, new C().arguments);
+ assertEquals(3, C.eval);
+ assertEquals(4, C.arguments);
+})();
+
+
+(function Setters() {
+ var x = 0;
+ class C {
+ set eval(v) {
+ x = v;
+ }
+ set arguments(v) {
+ x = v;
+ }
+ static set eval(v) {
+ x = v;
+ }
+ static set arguments(v) {
+ x = v;
+ }
+ };
+
+ new C().eval = 1;
+ assertEquals(1, x);
+ new C().arguments = 2;
+ assertEquals(2, x);
+ C.eval = 3;
+ assertEquals(3, x);
+ C.arguments = 4;
+ assertEquals(4, x);
+})();
--- /dev/null
+// 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.
+
+'use strict';
+(function TestArgumentsAccess() {
+ class Base {
+ constructor() {
+ assertEquals(2, arguments.length);
+ assertEquals(1, arguments[0]);
+ assertEquals(2, arguments[1]);
+ }
+ }
+
+ let b = new Base(1,2);
+
+ class Subclass extends Base {
+ constructor() {
+ assertEquals(2, arguments.length);
+ assertEquals(3, arguments[0]);
+ assertEquals(4, arguments[1]);
+ super(1,2);
+ }
+ }
+
+ let s = new Subclass(3,4);
+ assertEquals(0, Subclass.length);
+
+ class Subclass2 extends Base {
+ constructor(x,y) {
+ assertEquals(2, arguments.length);
+ assertEquals(3, arguments[0]);
+ assertEquals(4, arguments[1]);
+ super(1,2);
+ }
+ }
+
+ let s2 = new Subclass2(3,4);
+ assertEquals(2, Subclass2.length);
+}());
+
+(function TestThisAccessRestriction() {
+ class Base {
+ constructor(a, b) {
+ let o = new Object();
+ o.prp = a + b;
+ return o;
+ }
+ }
+
+ class Subclass extends Base {
+ constructor(a, b) {
+ var exn;
+ try {
+ this.prp1 = 3;
+ } catch (e) {
+ exn = e;
+ }
+ assertTrue(exn instanceof ReferenceError);
+ super(a, b);
+ assertSame(a + b, this.prp);
+ assertSame(undefined, this.prp1);
+ assertFalse(this.hasOwnProperty("prp1"));
+ return this;
+ }
+ }
+
+ let b = new Base(1, 2);
+ assertSame(3, b.prp);
+
+
+ let s = new Subclass(2, -1);
+ assertSame(1, s.prp);
+ assertSame(undefined, s.prp1);
+ assertFalse(s.hasOwnProperty("prp1"));
+
+ class Subclass2 extends Base {
+ constructor(x) {
+ super(1,2);
+
+ if (x < 0) return;
+
+ let called = false;
+ function tmp() { called = true; return 3; }
+ var exn = null;
+ try {
+ super(tmp(),4);
+ } catch (e) { exn = e; }
+ assertTrue(exn instanceof ReferenceError);
+ assertTrue(called);
+ }
+ }
+
+ var s2 = new Subclass2(1);
+ assertSame(3, s2.prp);
+
+ var s3 = new Subclass2(-1);
+ assertSame(3, s3.prp);
+
+ assertThrows(function() { Subclass.call(new Object(), 1, 2); }, TypeError);
+ assertThrows(function() { Base.call(new Object(), 1, 2); }, TypeError);
+
+ class BadSubclass extends Base {
+ constructor() {}
+ }
+
+ assertThrows(function() { new BadSubclass(); }, ReferenceError);
+}());
+
+(function TestThisCheckOrdering() {
+ let baseCalled = 0;
+ class Base {
+ constructor() { baseCalled++ }
+ }
+
+ let fCalled = 0;
+ function f() { fCalled++; return 3; }
+
+ class Subclass1 extends Base {
+ constructor() {
+ baseCalled = 0;
+ super();
+ assertEquals(1, baseCalled);
+ let obj = this;
+
+ let exn = null;
+ baseCalled = 0;
+ fCalled = 0;
+ try {
+ super(f());
+ } catch (e) { exn = e; }
+ assertTrue(exn instanceof ReferenceError);
+ assertEquals(1, fCalled);
+ assertEquals(1, baseCalled);
+ assertSame(obj, this);
+
+ exn = null;
+ baseCalled = 0;
+ fCalled = 0;
+ try {
+ super(super(), f());
+ } catch (e) { exn = e; }
+ assertTrue(exn instanceof ReferenceError);
+ assertEquals(0, fCalled);
+ assertEquals(1, baseCalled);
+ assertSame(obj, this);
+
+ exn = null;
+ baseCalled = 0;
+ fCalled = 0;
+ try {
+ super(f(), super());
+ } catch (e) { exn = e; }
+ assertTrue(exn instanceof ReferenceError);
+ assertEquals(1, fCalled);
+ assertEquals(1, baseCalled);
+ assertSame(obj, this);
+ }
+ }
+
+ new Subclass1();
+}());
+
+
+(function TestPrototypeWiring() {
+ class Base {
+ constructor(x) {
+ this.foobar = x;
+ }
+ }
+
+ class Subclass extends Base {
+ constructor(x) {
+ super(x);
+ }
+ }
+
+ let s = new Subclass(1);
+ assertSame(1, s.foobar);
+ assertSame(Subclass.prototype, s.__proto__);
+
+ let s1 = new Subclass(1, 2);
+ assertSame(1, s1.foobar);
+ assertTrue(s1.__proto__ === Subclass.prototype);
+
+ let s2 = new Subclass();
+ assertSame(undefined, s2.foobar);
+ assertSame(Subclass.prototype, s2.__proto__);
+ assertThrows(function() { Subclass(1); }, TypeError);
+ assertThrows(function() { Subclass(1,2,3,4); }, TypeError);
+
+ class Subclass2 extends Subclass {
+ constructor() {
+ super(5, 6, 7);
+ }
+ }
+
+ let ss2 = new Subclass2();
+ assertSame(5, ss2.foobar);
+ assertSame(Subclass2.prototype, ss2.__proto__);
+
+ class Subclass3 extends Base {
+ constructor(x,y) {
+ super(x + y);
+ }
+ }
+
+ let ss3 = new Subclass3(27,42-27);
+ assertSame(42, ss3.foobar);
+ assertSame(Subclass3.prototype, ss3.__proto__);
+}());
+
+(function TestSublclassingBuiltins() {
+ class ExtendedUint8Array extends Uint8Array {
+ constructor() {
+ super(10);
+ this[0] = 255;
+ this[1] = 0xFFA;
+ }
+ }
+
+ var eua = new ExtendedUint8Array();
+ assertEquals(10, eua.length);
+ assertEquals(10, eua.byteLength);
+ assertEquals(0xFF, eua[0]);
+ assertEquals(0xFA, eua[1]);
+ assertSame(ExtendedUint8Array.prototype, eua.__proto__);
+ assertEquals("[object Uint8Array]", Object.prototype.toString.call(eua));
+}());
+
+(function TestSubclassingNull() {
+ let N = null;
+
+ class Foo extends N {
+ constructor(x,y) {
+ assertSame(1, x);
+ assertSame(2, y);
+ return {};
+ }
+ }
+
+ new Foo(1,2);
+}());
+
+(function TestSubclassBinding() {
+ class Base {
+ constructor(x, y) {
+ this.x = x;
+ this.y = y;
+ }
+ }
+
+ let obj = {};
+ class Subclass extends Base {
+ constructor(x,y) {
+ super(x,y);
+ assertTrue(this !== obj);
+ }
+ }
+
+ let f = Subclass.bind(obj);
+ assertThrows(function () { f(1, 2); }, TypeError);
+ let s = new f(1, 2);
+ assertSame(1, s.x);
+ assertSame(2, s.y);
+ assertSame(Subclass.prototype, s.__proto__);
+
+ let s1 = new f(1);
+ assertSame(1, s1.x);
+ assertSame(undefined, s1.y);
+ assertSame(Subclass.prototype, s1.__proto__);
+
+ let g = Subclass.bind(obj, 1);
+ assertThrows(function () { g(8); }, TypeError);
+ let s2 = new g(8);
+ assertSame(1, s2.x);
+ assertSame(8, s2.y);
+ assertSame(Subclass.prototype, s.__proto__);
+}());
+
+
+(function TestDefaultConstructor() {
+ class Base1 { }
+ assertThrows(function() { Base1(); }, TypeError);
+
+ class Subclass1 extends Base1 { }
+
+ assertThrows(function() { Subclass1(); }, TypeError);
+
+ let s1 = new Subclass1();
+ assertSame(s1.__proto__, Subclass1.prototype);
+
+ class Base2 {
+ constructor(x, y) {
+ this.x = x;
+ this.y = y;
+ }
+ }
+
+ class Subclass2 extends Base2 {};
+
+ let s2 = new Subclass2(1, 2);
+
+ assertSame(s2.__proto__, Subclass2.prototype);
+ assertSame(1, s2.x);
+ assertSame(2, s2.y);
+
+ let f = Subclass2.bind({}, 3, 4);
+ let s2prime = new f();
+ assertSame(s2prime.__proto__, Subclass2.prototype);
+ assertSame(3, s2prime.x);
+ assertSame(4, s2prime.y);
+
+ let obj = {};
+ class Base3 {
+ constructor() {
+ return obj;
+ }
+ }
+
+ class Subclass3 extends Base3 {};
+
+ let s3 = new Subclass3();
+ assertSame(obj, s3);
+
+ class ExtendedUint8Array extends Uint8Array { }
+
+ var eua = new ExtendedUint8Array(10);
+ assertEquals(10, eua.length);
+ assertEquals(10, eua.byteLength);
+ eua[0] = 0xFF;
+ eua[1] = 0xFFA;
+ assertEquals(0xFF, eua[0]);
+ assertEquals(0xFA, eua[1]);
+ assertSame(ExtendedUint8Array.prototype, eua.__proto__);
+ assertEquals("[object Uint8Array]", Object.prototype.toString.call(eua));
+}());
--- /dev/null
+// 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: --min-preparse-length=0
+
+'use strict';
+
+class Base {
+ m() {
+ return 42;
+ }
+}
+
+class Derived extends Base {
+ m() {
+ return super.m();
+ }
+ evalM() {
+ return eval('super.m()');
+ }
+}
+
+assertEquals(42, new Derived().m());
+assertEquals(42, new Derived().evalM());
+
+
+class LazyDerived extends Base {
+ constructor() {
+ eval('super()');
+ }
+}
+assertInstanceof(new LazyDerived(), LazyDerived);
+assertInstanceof(new LazyDerived(), Base);
--- /dev/null
+// 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: --allow-natives-syntax
+'use strict';
+
+(function TestMaps() {
+ class Base {}
+ class Derived extends Base {}
+
+ let d1 = new Derived();
+ let d2 = new Derived();
+
+ assertTrue(%HaveSameMap(d1, d2));
+}());
+
+
+(function TestProtoModificationArray() {
+ let called = 0;
+ function F() {
+ called++;
+ assertFalse(Array.isArray(this));
+ }
+ class Derived extends Array {}
+ assertSame(Derived.__proto__, Array);
+
+ let d1 = new Derived();
+ assertTrue(Array.isArray(d1));
+
+ Derived.__proto__ = F;
+ called = 0;
+ let d2 = new Derived();
+ assertSame(1, called);
+ assertFalse(Array.isArray(d2));
+
+ assertFalse(%HaveSameMap(d1, d2));
+}());
+
+
+(function TestProtoModification() {
+ let called = 0;
+ function F() {
+ called++;
+ let exn = null;
+ try {
+ this.byteLength;
+ } catch (e) {
+ exn = e;
+ }
+ assertTrue(exn instanceof TypeError);
+ }
+ class Derived extends Uint8Array {
+ constructor() { super(10); }
+ }
+ assertSame(Derived.__proto__, Uint8Array);
+
+ let d1 = new Derived();
+ assertSame(10, d1.byteLength);
+
+ Derived.__proto__ = F;
+ called = 0;
+ let d2 = new Derived();
+ assertSame(1, called);
+ assertThrows(function() { d2.byteLength; }, TypeError);
+
+ assertFalse(%HaveSameMap(d1, d2));
+}());
--- /dev/null
+// Copyright 2015 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.
+
+'use strict';
+
+(function TestDefaultConstructor() {
+ class Stack extends Array { }
+ {
+ let s1 = new Stack();
+ assertSame(Stack.prototype, s1.__proto__);
+ assertTrue(Array.isArray(s1));
+ assertSame(0, s1.length);
+ s1[0] = 'xyz';
+ assertSame(1, s1.length);
+ assertSame('xyz', s1[0]);
+ s1.push(42);
+ assertSame(2, s1.length);
+ assertSame('xyz', s1[0]);
+ assertSame(42, s1[1]);
+ }
+
+ {
+ let s2 = new Stack(10);
+ assertSame(Stack.prototype, s2.__proto__);
+ assertTrue(Array.isArray(s2));
+ assertSame(10, s2.length);
+ assertSame(undefined, s2[0]);
+ }
+
+ {
+ let a = [1,2,3];
+ let s3 = new Stack(a);
+ assertSame(Stack.prototype, s3.__proto__);
+ assertTrue(Array.isArray(s3));
+ assertSame(1, s3.length);
+ assertSame(a, s3[0]);
+ }
+
+ {
+ let s4 = new Stack(1, 2, 3);
+ assertSame(Stack.prototype, s4.__proto__);
+ assertTrue(Array.isArray(s4));
+ assertSame(3, s4.length);
+ assertSame(1, s4[0]);
+ assertSame(2, s4[1]);
+ assertSame(3, s4[2]);
+ }
+
+ {
+ let s5 = new Stack(undefined, undefined, undefined);
+ assertSame(Stack.prototype, s5.__proto__);
+ assertTrue(Array.isArray(s5));
+ assertSame(3, s5.length);
+ assertSame(undefined, s5[0]);
+ assertSame(undefined, s5[1]);
+ assertSame(undefined, s5[2]);
+ }
+}());
+
+
+(function TestEmptyArgsSuper() {
+ class Stack extends Array {
+ constructor() { super(); }
+ }
+ let s1 = new Stack();
+ assertSame(Stack.prototype, s1.__proto__);
+ assertTrue(Array.isArray(s1));
+ assertSame(0, s1.length);
+ s1[0] = 'xyz';
+ assertSame(1, s1.length);
+ assertSame('xyz', s1[0]);
+ s1.push(42);
+ assertSame(2, s1.length);
+ assertSame('xyz', s1[0]);
+ assertSame(42, s1[1]);
+}());
+
+
+(function TestOneArgSuper() {
+ class Stack extends Array {
+ constructor(x) {
+ super(x);
+ }
+ }
+
+ {
+ let s2 = new Stack(10, 'ignored arg');
+ assertSame(Stack.prototype, s2.__proto__);
+ assertTrue(Array.isArray(s2));
+ assertSame(10, s2.length);
+ assertSame(undefined, s2[0]);
+ }
+
+ {
+ let a = [1,2,3];
+ let s3 = new Stack(a, 'ignored arg');
+ assertSame(Stack.prototype, s3.__proto__);
+ assertTrue(Array.isArray(s3));
+ assertSame(1, s3.length);
+ assertSame(a, s3[0]);
+ }
+}());
+
+
+(function TestMultipleArgsSuper() {
+ class Stack extends Array {
+ constructor(x, y, z) {
+ super(x, y, z);
+ }
+ }
+ {
+ let s4 = new Stack(1, 2, 3, 4, 5);
+ assertSame(Stack.prototype, s4.__proto__);
+ assertTrue(Array.isArray(s4));
+ assertSame(3, s4.length);
+ assertSame(1, s4[0]);
+ assertSame(2, s4[1]);
+ assertSame(3, s4[2]);
+ }
+
+ {
+ let s5 = new Stack(undefined);
+ assertSame(Stack.prototype, s5.__proto__);
+ assertTrue(Array.isArray(s5));
+ assertTrue(s5.__proto__ == Stack.prototype);
+ assertSame(3, s5.length);
+ assertSame(undefined, s5[0]);
+ assertSame(undefined, s5[1]);
+ assertSame(undefined, s5[2]);
+ }
+}());
+
+
+(function TestArrayConcat() {
+ class Stack extends Array { }
+ let s1 = new Stack(1,2,3);
+
+ assertArrayEquals([1,2,3,4,5,6], s1.concat([4,5,6]));
+ assertArrayEquals([4,5,6,1,2,3], [4,5,6].concat(s1));
+}());
+
+
+(function TestJSONStringify() {
+ class Stack extends Array { }
+
+ let s1 = new Stack(1,2,3);
+ assertSame("[1,2,3]", JSON.stringify(s1));
+}());
--- /dev/null
+// 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-sloppy
+
+(function TestBasics() {
+ var C = class C {}
+ assertEquals(typeof C, 'function');
+ assertEquals(C.__proto__, Function.prototype);
+ assertEquals(Object.prototype, Object.getPrototypeOf(C.prototype));
+ assertEquals(Function.prototype, Object.getPrototypeOf(C));
+ assertEquals('C', C.name);
+
+ class D {}
+ assertEquals(typeof D, 'function');
+ assertEquals(D.__proto__, Function.prototype);
+ assertEquals(Object.prototype, Object.getPrototypeOf(D.prototype));
+ assertEquals(Function.prototype, Object.getPrototypeOf(D));
+ assertEquals('D', D.name);
+
+ class D2 { constructor() {} }
+ assertEquals('D2', D2.name);
+
+ // TODO(arv): The logic for the name of anonymous functions in ES6 requires
+ // the below to be 'E';
+ var E = class {}
+ assertEquals('', E.name); // Should be 'E'.
+
+ var F = class { constructor() {} };
+ assertEquals('', F.name); // Should be 'F'.
+})();
+
+
+(function TestBasicsExtends() {
+ class C extends null {}
+ assertEquals(typeof C, 'function');
+ assertEquals(C.__proto__, Function.prototype);
+ assertEquals(null, Object.getPrototypeOf(C.prototype));
+
+ class D extends C {}
+ assertEquals(typeof D, 'function');
+ assertEquals(D.__proto__, C);
+ assertEquals(C.prototype, Object.getPrototypeOf(D.prototype));
+})();
+
+
+(function TestSideEffectInExtends() {
+ var calls = 0;
+ class C {}
+ class D extends (calls++, C) {}
+ assertEquals(1, calls);
+ assertEquals(typeof D, 'function');
+ assertEquals(D.__proto__, C);
+ assertEquals(C.prototype, Object.getPrototypeOf(D.prototype));
+})();
+
+
+(function TestInvalidExtends() {
+ assertThrows(function() {
+ class C extends 42 {}
+ }, TypeError);
+
+ assertThrows(function() {
+ // Function but its .prototype is not null or a function.
+ class C extends Math.abs {}
+ }, TypeError);
+
+ assertThrows(function() {
+ Math.abs.prototype = 42;
+ class C extends Math.abs {}
+ }, TypeError);
+ delete Math.abs.prototype;
+
+ assertThrows(function() {
+ function* g() {}
+ class C extends g {}
+ }, TypeError);
+})();
+
+
+(function TestConstructorProperty() {
+ class C {}
+ assertEquals(C, C.prototype.constructor);
+ var descr = Object.getOwnPropertyDescriptor(C.prototype, 'constructor');
+ assertTrue(descr.configurable);
+ assertFalse(descr.enumerable);
+ assertTrue(descr.writable);
+})();
+
+
+(function TestPrototypeProperty() {
+ class C {}
+ var descr = Object.getOwnPropertyDescriptor(C, 'prototype');
+ assertFalse(descr.configurable);
+ assertFalse(descr.enumerable);
+ assertFalse(descr.writable);
+})();
+
+
+(function TestConstructor() {
+ var count = 0;
+ class C {
+ constructor() {
+ assertEquals(Object.getPrototypeOf(this), C.prototype);
+ count++;
+ }
+ }
+ assertEquals(C, C.prototype.constructor);
+ var descr = Object.getOwnPropertyDescriptor(C.prototype, 'constructor');
+ assertTrue(descr.configurable);
+ assertFalse(descr.enumerable);
+ assertTrue(descr.writable);
+
+ var c = new C();
+ assertEquals(1, count);
+ assertEquals(Object.getPrototypeOf(c), C.prototype);
+})();
+
+
+(function TestImplicitConstructor() {
+ class C {}
+ var c = new C();
+ assertEquals(Object.getPrototypeOf(c), C.prototype);
+})();
+
+
+(function TestConstructorStrict() {
+ class C {
+ constructor() {
+ assertThrows(function() {
+ nonExistingBinding = 42;
+ }, ReferenceError);
+ }
+ }
+ new C();
+})();
+
+
+(function TestSuperInConstructor() {
+ var calls = 0;
+ class B {}
+ B.prototype.x = 42;
+
+ class C extends B {
+ constructor() {
+ super();
+ calls++;
+ assertEquals(42, super.x);
+ }
+ }
+
+ new C;
+ assertEquals(1, calls);
+})();
+
+
+(function TestStrictMode() {
+ class C {}
+
+ with ({a: 1}) {
+ assertEquals(1, a);
+ }
+
+ assertThrows('class C extends function B() { with ({}); return B; }() {}',
+ SyntaxError);
+
+ var D = class extends function() {
+ arguments.caller;
+ } {};
+ assertThrows(function() {
+ Object.getPrototypeOf(D).arguments;
+ }, TypeError);
+ assertThrows(function() {
+ new D;
+ }, TypeError);
+})();
+
+
+(function TestToString() {
+ class C {}
+ assertEquals('class C {}', C.toString());
+
+ class D { constructor() { 42; } }
+ assertEquals('class D { constructor() { 42; } }', D.toString());
+
+ class E { x() { 42; } }
+ assertEquals('class E { x() { 42; } }', E.toString());
+})();
+
+
+function assertMethodDescriptor(object, name) {
+ var descr = Object.getOwnPropertyDescriptor(object, name);
+ assertTrue(descr.configurable);
+ assertFalse(descr.enumerable);
+ assertTrue(descr.writable);
+ assertEquals('function', typeof descr.value);
+ assertFalse('prototype' in descr.value);
+}
+
+
+function assertGetterDescriptor(object, name) {
+ var descr = Object.getOwnPropertyDescriptor(object, name);
+ assertTrue(descr.configurable);
+ assertFalse(descr.enumerable);
+ assertEquals('function', typeof descr.get);
+ assertFalse('prototype' in descr.get);
+ assertEquals(undefined, descr.set);
+}
+
+
+function assertSetterDescriptor(object, name) {
+ var descr = Object.getOwnPropertyDescriptor(object, name);
+ assertTrue(descr.configurable);
+ assertFalse(descr.enumerable);
+ assertEquals(undefined, descr.get);
+ assertEquals('function', typeof descr.set);
+ assertFalse('prototype' in descr.set);
+}
+
+
+function assertAccessorDescriptor(object, name) {
+ var descr = Object.getOwnPropertyDescriptor(object, name);
+ assertTrue(descr.configurable);
+ assertFalse(descr.enumerable);
+ assertEquals('function', typeof descr.get);
+ assertEquals('function', typeof descr.set);
+ assertFalse('prototype' in descr.get);
+ assertFalse('prototype' in descr.set);
+}
+
+
+(function TestMethods() {
+ class C {
+ method() { return 1; }
+ static staticMethod() { return 2; }
+ method2() { return 3; }
+ static staticMethod2() { return 4; }
+ }
+
+ assertMethodDescriptor(C.prototype, 'method');
+ assertMethodDescriptor(C.prototype, 'method2');
+ assertMethodDescriptor(C, 'staticMethod');
+ assertMethodDescriptor(C, 'staticMethod2');
+
+ assertEquals(1, new C().method());
+ assertEquals(2, C.staticMethod());
+ assertEquals(3, new C().method2());
+ assertEquals(4, C.staticMethod2());
+})();
+
+
+(function TestGetters() {
+ class C {
+ get x() { return 1; }
+ static get staticX() { return 2; }
+ get y() { return 3; }
+ static get staticY() { return 4; }
+ }
+
+ assertGetterDescriptor(C.prototype, 'x');
+ assertGetterDescriptor(C.prototype, 'y');
+ assertGetterDescriptor(C, 'staticX');
+ assertGetterDescriptor(C, 'staticY');
+
+ assertEquals(1, new C().x);
+ assertEquals(2, C.staticX);
+ assertEquals(3, new C().y);
+ assertEquals(4, C.staticY);
+})();
+
+
+
+(function TestSetters() {
+ var x, staticX, y, staticY;
+ class C {
+ set x(v) { x = v; }
+ static set staticX(v) { staticX = v; }
+ set y(v) { y = v; }
+ static set staticY(v) { staticY = v; }
+ }
+
+ assertSetterDescriptor(C.prototype, 'x');
+ assertSetterDescriptor(C.prototype, 'y');
+ assertSetterDescriptor(C, 'staticX');
+ assertSetterDescriptor(C, 'staticY');
+
+ assertEquals(1, new C().x = 1);
+ assertEquals(1, x);
+ assertEquals(2, C.staticX = 2);
+ assertEquals(2, staticX);
+ assertEquals(3, new C().y = 3);
+ assertEquals(3, y);
+ assertEquals(4, C.staticY = 4);
+ assertEquals(4, staticY);
+})();
+
+
+(function TestSideEffectsInPropertyDefine() {
+ function B() {}
+ B.prototype = {
+ constructor: B,
+ set m(v) {
+ throw Error();
+ }
+ };
+
+ class C extends B {
+ m() { return 1; }
+ }
+
+ assertEquals(1, new C().m());
+})();
+
+
+(function TestAccessors() {
+ class C {
+ constructor(x) {
+ this._x = x;
+ }
+
+ get x() { return this._x; }
+ set x(v) { this._x = v; }
+
+ static get staticX() { return this._x; }
+ static set staticX(v) { this._x = v; }
+ }
+
+ assertAccessorDescriptor(C.prototype, 'x');
+ assertAccessorDescriptor(C, 'staticX');
+
+ var c = new C(1);
+ c._x = 1;
+ assertEquals(1, c.x);
+ c.x = 2;
+ assertEquals(2, c._x);
+
+ C._x = 3;
+ assertEquals(3, C.staticX);
+ C._x = 4;
+ assertEquals(4, C.staticX );
+})();
+
+
+(function TestProto() {
+ class C {
+ __proto__() { return 1; }
+ }
+ assertMethodDescriptor(C.prototype, '__proto__');
+ assertEquals(1, new C().__proto__());
+})();
+
+
+(function TestProtoStatic() {
+ class C {
+ static __proto__() { return 1; }
+ }
+ assertMethodDescriptor(C, '__proto__');
+ assertEquals(1, C.__proto__());
+})();
+
+
+(function TestProtoAccessor() {
+ class C {
+ get __proto__() { return this._p; }
+ set __proto__(v) { this._p = v; }
+ }
+ assertAccessorDescriptor(C.prototype, '__proto__');
+ var c = new C();
+ c._p = 1;
+ assertEquals(1, c.__proto__);
+ c.__proto__ = 2;
+ assertEquals(2, c.__proto__);
+})();
+
+
+(function TestStaticProtoAccessor() {
+ class C {
+ static get __proto__() { return this._p; }
+ static set __proto__(v) { this._p = v; }
+ }
+ assertAccessorDescriptor(C, '__proto__');
+ C._p = 1;
+ assertEquals(1, C.__proto__);
+ C.__proto__ = 2;
+ assertEquals(2, C.__proto__);
+})();
+
+
+(function TestSettersOnProto() {
+ function Base() {}
+ Base.prototype = {
+ set constructor(_) {
+ assertUnreachable();
+ },
+ set m(_) {
+ assertUnreachable();
+ }
+ };
+ Object.defineProperty(Base, 'staticM', {
+ set: function() {
+ assertUnreachable();
+ }
+ });
+
+ class C extends Base {
+ m() {
+ return 1;
+ }
+ static staticM() {
+ return 2;
+ }
+ }
+
+ assertEquals(1, new C().m());
+ assertEquals(2, C.staticM());
+})();
+
+
+(function TestConstructableButNoPrototype() {
+ var Base = function() {}.bind();
+ assertThrows(function() {
+ class C extends Base {}
+ }, TypeError);
+})();
+
+
+(function TestPrototypeGetter() {
+ var calls = 0;
+ var Base = function() {}.bind();
+ Object.defineProperty(Base, 'prototype', {
+ get: function() {
+ calls++;
+ return null;
+ },
+ configurable: true
+ });
+ class C extends Base {}
+ assertEquals(1, calls);
+
+ calls = 0;
+ Object.defineProperty(Base, 'prototype', {
+ get: function() {
+ calls++;
+ return 42;
+ },
+ configurable: true
+ });
+ assertThrows(function() {
+ class C extends Base {}
+ }, TypeError);
+ assertEquals(1, calls);
+})();
+
+
+(function TestPrototypeSetter() {
+ var Base = function() {}.bind();
+ Object.defineProperty(Base, 'prototype', {
+ set: function() {
+ assertUnreachable();
+ }
+ });
+ assertThrows(function() {
+ class C extends Base {}
+ }, TypeError);
+})();
+
+
+(function TestSuperInMethods() {
+ class B {
+ method() {
+ return 1;
+ }
+ get x() {
+ return 2;
+ }
+ }
+ class C extends B {
+ method() {
+ assertEquals(2, super.x);
+ return super.method();
+ }
+ }
+ assertEquals(1, new C().method());
+})();
+
+
+(function TestSuperInGetter() {
+ class B {
+ method() {
+ return 1;
+ }
+ get x() {
+ return 2;
+ }
+ }
+ class C extends B {
+ get y() {
+ assertEquals(2, super.x);
+ return super.method();
+ }
+ }
+ assertEquals(1, new C().y);
+})();
+
+
+(function TestSuperInSetter() {
+ class B {
+ method() {
+ return 1;
+ }
+ get x() {
+ return 2;
+ }
+ }
+ class C extends B {
+ set y(v) {
+ assertEquals(3, v);
+ assertEquals(2, super.x);
+ assertEquals(1, super.method());
+ }
+ }
+ assertEquals(3, new C().y = 3);
+})();
+
+
+(function TestSuperInStaticMethods() {
+ class B {
+ static method() {
+ return 1;
+ }
+ static get x() {
+ return 2;
+ }
+ }
+ class C extends B {
+ static method() {
+ assertEquals(2, super.x);
+ return super.method();
+ }
+ }
+ assertEquals(1, C.method());
+})();
+
+
+(function TestSuperInStaticGetter() {
+ class B {
+ static method() {
+ return 1;
+ }
+ static get x() {
+ return 2;
+ }
+ }
+ class C extends B {
+ static get x() {
+ assertEquals(2, super.x);
+ return super.method();
+ }
+ }
+ assertEquals(1, C.x);
+})();
+
+
+(function TestSuperInStaticSetter() {
+ class B {
+ static method() {
+ return 1;
+ }
+ static get x() {
+ return 2;
+ }
+ }
+ class C extends B {
+ static set x(v) {
+ assertEquals(3, v);
+ assertEquals(2, super.x);
+ assertEquals(1, super.method());
+ }
+ }
+ assertEquals(3, C.x = 3);
+})();
+
+
+(function TestNumericPropertyNames() {
+ class B {
+ 1() { return 1; }
+ get 2() { return 2; }
+ set 3(_) {}
+
+ static 4() { return 4; }
+ static get 5() { return 5; }
+ static set 6(_) {}
+ }
+
+ assertMethodDescriptor(B.prototype, '1');
+ assertGetterDescriptor(B.prototype, '2');
+ assertSetterDescriptor(B.prototype, '3');
+
+ assertMethodDescriptor(B, '4');
+ assertGetterDescriptor(B, '5');
+ assertSetterDescriptor(B, '6');
+
+ class C extends B {
+ 1() { return super[1](); }
+ get 2() { return super[2]; }
+
+ static 4() { return super[4](); }
+ static get 5() { return super[5]; }
+ }
+
+ assertEquals(1, new C()[1]());
+ assertEquals(2, new C()[2]);
+ assertEquals(4, C[4]());
+ assertEquals(5, C[5]);
+})();
+
+
+(function TestDefaultConstructorNoCrash() {
+ // Regression test for https://code.google.com/p/v8/issues/detail?id=3661
+ class C {}
+ assertThrows(function () {C();}, TypeError);
+ assertThrows(function () {C(1);}, TypeError);
+ assertTrue(new C() instanceof C);
+ assertTrue(new C(1) instanceof C);
+})();
+
+
+(function TestDefaultConstructor() {
+ var calls = 0;
+ class Base {
+ constructor() {
+ calls++;
+ }
+ }
+ class Derived extends Base {}
+ var object = new Derived;
+ assertEquals(1, calls);
+
+ calls = 0;
+ assertThrows(function() { Derived(); }, TypeError);
+ assertEquals(0, calls);
+})();
+
+
+(function TestDefaultConstructorArguments() {
+ var args, self;
+ class Base {
+ constructor() {
+ self = this;
+ args = arguments;
+ }
+ }
+ class Derived extends Base {}
+
+ new Derived;
+ assertEquals(0, args.length);
+
+ new Derived(0, 1, 2);
+ assertEquals(3, args.length);
+ assertTrue(self instanceof Derived);
+
+ var arr = new Array(100);
+ var obj = {};
+ assertThrows(function() {Derived.apply(obj, arr);}, TypeError);
+})();
+
+
+(function TestDefaultConstructorArguments2() {
+ var args;
+ class Base {
+ constructor(x, y) {
+ args = arguments;
+ }
+ }
+ class Derived extends Base {}
+
+ new Derived;
+ assertEquals(0, args.length);
+
+ new Derived(1);
+ assertEquals(1, args.length);
+ assertEquals(1, args[0]);
+
+ new Derived(1, 2, 3);
+ assertEquals(3, args.length);
+ assertEquals(1, args[0]);
+ assertEquals(2, args[1]);
+ assertEquals(3, args[2]);
+})();
+
+
+(function TestNameBindingConst() {
+ assertThrows('class C { constructor() { C = 42; } }; new C();', TypeError);
+ assertThrows('new (class C { constructor() { C = 42; } })', TypeError);
+ assertThrows('class C { m() { C = 42; } }; new C().m()', TypeError);
+ assertThrows('new (class C { m() { C = 42; } }).m()', TypeError);
+ assertThrows('class C { get x() { C = 42; } }; new C().x', TypeError);
+ assertThrows('(new (class C { get x() { C = 42; } })).x', TypeError);
+ assertThrows('class C { set x(_) { C = 42; } }; new C().x = 15;', TypeError);
+ assertThrows('(new (class C { set x(_) { C = 42; } })).x = 15;', TypeError);
+})();
+
+
+(function TestNameBinding() {
+ var C2;
+ class C {
+ constructor() {
+ C2 = C;
+ }
+ m() {
+ C2 = C;
+ }
+ get x() {
+ C2 = C;
+ }
+ set x(_) {
+ C2 = C;
+ }
+ }
+ new C();
+ assertEquals(C, C2);
+
+ C2 = undefined;
+ new C().m();
+ assertEquals(C, C2);
+
+ C2 = undefined;
+ new C().x;
+ assertEquals(C, C2);
+
+ C2 = undefined;
+ new C().x = 1;
+ assertEquals(C, C2);
+})();
+
+
+(function TestNameBindingExpression() {
+ var C3;
+ var C = class C2 {
+ constructor() {
+ assertEquals(C2, C);
+ C3 = C2;
+ }
+ m() {
+ assertEquals(C2, C);
+ C3 = C2;
+ }
+ get x() {
+ assertEquals(C2, C);
+ C3 = C2;
+ }
+ set x(_) {
+ assertEquals(C2, C);
+ C3 = C2;
+ }
+ }
+ new C();
+ assertEquals(C, C3);
+
+ C3 = undefined;
+ new C().m();
+ assertEquals(C, C3);
+
+ C3 = undefined;
+ new C().x;
+ assertEquals(C, C3);
+
+ C3 = undefined;
+ new C().x = 1;
+ assertEquals(C, C3);
+})();
+
+
+(function TestNameBindingInExtendsExpression() {
+ assertThrows(function() {
+ class x extends x {}
+ }, ReferenceError);
+
+ assertThrows(function() {
+ (class x extends x {});
+ }, ReferenceError);
+
+ assertThrows(function() {
+ var x = (class x extends x {});
+ }, ReferenceError);
+})();
+
+
+(function TestThisAccessRestriction() {
+ class Base {}
+ (function() {
+ class C extends Base {
+ constructor() {
+ var y;
+ super();
+ }
+ }; new C();
+ }());
+ assertThrows(function() {
+ class C extends Base {
+ constructor() {
+ super(this.x);
+ }
+ }; new C();
+ }, ReferenceError);
+ assertThrows(function() {
+ class C extends Base {
+ constructor() {
+ super(this);
+ }
+ }; new C();
+ }, ReferenceError);
+ assertThrows(function() {
+ class C extends Base {
+ constructor() {
+ super.method();
+ super(this);
+ }
+ }; new C();
+ }, ReferenceError);
+ assertThrows(function() {
+ class C extends Base {
+ constructor() {
+ super(super.method());
+ }
+ }; new C();
+ }, ReferenceError);
+ assertThrows(function() {
+ class C extends Base {
+ constructor() {
+ super(super());
+ }
+ }; new C();
+ }, ReferenceError);
+ assertThrows(function() {
+ class C extends Base {
+ constructor() {
+ super(1, 2, Object.getPrototypeOf(this));
+ }
+ }; new C();
+ }, ReferenceError);
+ (function() {
+ class C extends Base {
+ constructor() {
+ { super(1, 2); }
+ }
+ }; new C();
+ }());
+ (function() {
+ class C extends Base {
+ constructor() {
+ if (1) super();
+ }
+ }; new C();
+ }());
+
+ class C1 extends Object {
+ constructor() {
+ 'use strict';
+ super();
+ }
+ };
+ new C1();
+
+ class C2 extends Object {
+ constructor() {
+ ; 'use strict';;;;;
+ super();
+ }
+ };
+ new C2();
+
+ class C3 extends Object {
+ constructor() {
+ ; 'use strict';;;;;
+ // This is a comment.
+ super();
+ }
+ };
+ new C3();
+}());
+
+
+function testClassRestrictedProperties(C) {
+ assertEquals(false, C.hasOwnProperty("arguments"));
+ assertThrows(function() { return C.arguments; }, TypeError);
+ assertThrows(function() { C.arguments = {}; }, TypeError);
+
+ assertEquals(false, C.hasOwnProperty("caller"));
+ assertThrows(function() { return C.caller; }, TypeError);
+ assertThrows(function() { C.caller = {}; }, TypeError);
+
+ assertEquals(false, (new C).method.hasOwnProperty("arguments"));
+ assertThrows(function() { return new C().method.arguments; }, TypeError);
+ assertThrows(function() { new C().method.arguments = {}; }, TypeError);
+
+ assertEquals(false, (new C).method.hasOwnProperty("caller"));
+ assertThrows(function() { return new C().method.caller; }, TypeError);
+ assertThrows(function() { new C().method.caller = {}; }, TypeError);
+}
+
+
+(function testRestrictedPropertiesStrict() {
+ "use strict";
+ class ClassWithDefaultConstructor {
+ method() {}
+ }
+ class Class {
+ constructor() {}
+ method() {}
+ }
+ class DerivedClassWithDefaultConstructor extends Class {}
+ class DerivedClass extends Class { constructor() { super(); } }
+
+ testClassRestrictedProperties(ClassWithDefaultConstructor);
+ testClassRestrictedProperties(Class);
+ testClassRestrictedProperties(DerivedClassWithDefaultConstructor);
+ testClassRestrictedProperties(DerivedClass);
+ testClassRestrictedProperties(class { method() {} });
+ testClassRestrictedProperties(class { constructor() {} method() {} });
+ testClassRestrictedProperties(class extends Class { });
+ testClassRestrictedProperties(
+ class extends Class { constructor() { super(); } });
+})();
+
+
+(function testRestrictedPropertiesSloppy() {
+ class ClassWithDefaultConstructor {
+ method() {}
+ }
+ class Class {
+ constructor() {}
+ method() {}
+ }
+ class DerivedClassWithDefaultConstructor extends Class {}
+ class DerivedClass extends Class { constructor() { super(); } }
+
+ testClassRestrictedProperties(ClassWithDefaultConstructor);
+ testClassRestrictedProperties(Class);
+ testClassRestrictedProperties(DerivedClassWithDefaultConstructor);
+ testClassRestrictedProperties(DerivedClass);
+ testClassRestrictedProperties(class { method() {} });
+ testClassRestrictedProperties(class { constructor() {} method() {} });
+ testClassRestrictedProperties(class extends Class { });
+ testClassRestrictedProperties(
+ class extends Class { constructor() { super(); } });
+})();
--- /dev/null
+// 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: --expose-debug-as debug
+
+'use strict';
+
+var Debug = debug.Debug
+
+var done = false;
+var stepCount = 0;
+
+function listener(event, execState, eventData, data) {
+ if (event == Debug.DebugEvent.Break) {
+ if (!done) {
+ execState.prepareStep(Debug.StepAction.StepInto);
+ var s = execState.frame().sourceLineText();
+ assertTrue(s.indexOf('// ' + stepCount + '.') !== -1);
+ stepCount++;
+ }
+ }
+};
+
+Debug.setListener(listener);
+
+function GetBase() {
+ var x = 1; // 1.
+ var y = 2; // 2.
+ done = true; // 3.
+ return null;
+}
+
+function f() {
+ class Derived extends GetBase() {} // 0.
+}
+
+var bp = Debug.setBreakPoint(f, 0);
+f();
+assertEquals(4, stepCount);
+
+Debug.setListener(null);
--- /dev/null
+// 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: --expose-debug-as debug
+
+'use strict';
+
+var Debug = debug.Debug
+var done, stepCount;
+
+function listener(event, execState, eventData, data) {
+ if (event == Debug.DebugEvent.Break) {
+ if (!done) {
+ execState.prepareStep(Debug.StepAction.StepInto);
+ var s = execState.frame().sourceLineText();
+ assertTrue(s.indexOf('// ' + stepCount + '.') !== -1);
+ stepCount++;
+ }
+ }
+};
+
+Debug.setListener(listener);
+
+
+class Base {
+ constructor() {
+ var x = 1; // 1.
+ var y = 2; // 2.
+ done = true; // 3.
+ }
+}
+
+class Derived extends Base {}
+
+
+(function TestBreakPointInConstructor() {
+ done = false;
+ stepCount = 1;
+ var bp = Debug.setBreakPoint(Base, 0);
+
+ new Base();
+ assertEquals(4, stepCount);
+
+ Debug.clearBreakPoint(bp);
+})();
+
+
+(function TestDefaultConstructor() {
+ done = false;
+ stepCount = 1;
+
+ var bp = Debug.setBreakPoint(Base, 0);
+ new Derived();
+ assertEquals(4, stepCount);
+
+ Debug.clearBreakPoint(bp);
+})();
+
+
+(function TestStepInto() {
+ done = false;
+ stepCount = 0;
+
+ function f() {
+ new Derived(); // 0.
+ }
+
+ var bp = Debug.setBreakPoint(f, 0);
+ f();
+ assertEquals(4, stepCount);
+
+ Debug.clearBreakPoint(bp);
+})();
+
+
+(function TestExtraIndirection() {
+ done = false;
+ stepCount = 0;
+
+ class Derived2 extends Derived {}
+
+ function f() {
+ new Derived2(); // 0.
+ }
+
+ var bp = Debug.setBreakPoint(f, 0);
+ f();
+ assertEquals(4, stepCount);
+
+ Debug.clearBreakPoint(bp);
+})();
+
+
+(function TestBoundClass() {
+ done = false;
+ stepCount = 0;
+
+ var bound = Derived.bind(null);
+
+ function f() {
+ new bound(); // 0.
+ }
+
+ var bp = Debug.setBreakPoint(f, 0);
+ f();
+ assertEquals(4, stepCount);
+
+ Debug.clearBreakPoint(bp);
+})();
+
+
+Debug.setListener(null);
--- /dev/null
+// 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.
+
+'use strict';
+class Example { }
+Object.observe(Example.prototype, function(){});
--- /dev/null
+// Copyright 2015 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: --no-lazy
+"use strict";
+class Base {
+}
+class Subclass extends Base {
+ constructor() {
+ this.prp1 = 3;
+ }
+}
+function __f_1(){
+}
--- /dev/null
+// 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: --allow-natives-syntax
+
+
+(function TestSingleClass() {
+ function f(x) {
+ var a = [0, 1, 2]
+ return a[x];
+ }
+
+ function ClassD() { }
+
+ assertEquals(1, f(1));
+ var g = %ToMethod(f, ClassD.prototype);
+ assertEquals(1, g(1));
+ assertEquals(undefined, f[%HomeObjectSymbol()]);
+ assertEquals(ClassD.prototype, g[%HomeObjectSymbol()]);
+}());
+
+
+(function TestClassHierarchy() {
+ function f(x) {
+ return function g(y) { x++; return x + y; };
+ }
+
+ function Base() {}
+ function Derived() { }
+ Derived.prototype = Object.create(Base.prototype);
+
+ var q = f(0);
+ assertEquals(2, q(1));
+ assertEquals(3, q(1));
+ var g = %ToMethod(q, Derived.prototype);
+ assertFalse(g === q);
+ assertEquals(4, g(1));
+ assertEquals(5, q(1));
+}());
+
+
+(function TestPrototypeChain() {
+ var o = {};
+ var o1 = {};
+ function f() { }
+
+ function g() { }
+
+ var fMeth = %ToMethod(f, o);
+ assertEquals(o, fMeth[%HomeObjectSymbol()]);
+ g.__proto__ = fMeth;
+ assertEquals(undefined, g[%HomeObjectSymbol()]);
+ var gMeth = %ToMethod(g, o1);
+ assertEquals(fMeth, gMeth.__proto__);
+ assertEquals(o, fMeth[%HomeObjectSymbol()]);
+ assertEquals(o1, gMeth[%HomeObjectSymbol()]);
+}());
+
+
+(function TestBoundFunction() {
+ var o = {};
+ var p = {};
+
+
+ function f(x, y, z, w) {
+ assertEquals(o, this);
+ assertEquals(1, x);
+ assertEquals(2, y);
+ assertEquals(3, z);
+ assertEquals(4, w);
+ return x+y+z+w;
+ }
+
+ var fBound = f.bind(o, 1, 2, 3);
+ var fMeth = %ToMethod(fBound, p);
+ assertEquals(10, fMeth(4));
+ assertEquals(10, fMeth.call(p, 4));
+ var fBound1 = fBound.bind(o, 4);
+ assertEquals(10, fBound1());
+ var fMethBound = fMeth.bind(o, 4);
+ assertEquals(10, fMethBound());
+}());
+
+(function TestOptimized() {
+ function f(o) {
+ return o.x;
+ }
+ var o = {x : 15};
+ assertEquals(15, f(o));
+ assertEquals(15, f(o));
+ %OptimizeFunctionOnNextCall(f);
+ assertEquals(15, f(o));
+ var g = %ToMethod(f, {});
+ var o1 = {y : 1024, x : "abc"};
+ assertEquals("abc", f(o1));
+ assertEquals("abc", g(o1));
+} ());
+
+(function TestExtensibility() {
+ function f() {}
+ Object.preventExtensions(f);
+ assertFalse(Object.isExtensible(f));
+ var m = %ToMethod(f, {});
+ assertTrue(Object.isExtensible(m));
+}());
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Flags: --harmony-arrays --harmony-classes
+// Flags: --harmony-arrays
(function testArrayConcatArity() {
"use strict";
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Flags: --harmony-arrow-functions --harmony-classes
+// Flags: --harmony-arrow-functions
(function testInFunctionDeclaration() {
// found in the LICENSE file.
// Flags: --harmony-computed-property-names --harmony-sloppy
-// Flags: --harmony-classes --allow-natives-syntax
+// Flags: --allow-natives-syntax
function ID(x) {
+++ /dev/null
-// Copyright 2015 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-classes --harmony-sloppy
-
-
-(function Method() {
- class C {
- eval() {
- return 1;
- }
- arguments() {
- return 2;
- }
- static eval() {
- return 3;
- }
- static arguments() {
- return 4;
- }
- };
-
- assertEquals(1, new C().eval());
- assertEquals(2, new C().arguments());
- assertEquals(3, C.eval());
- assertEquals(4, C.arguments());
-})();
-
-
-(function Getters() {
- class C {
- get eval() {
- return 1;
- }
- get arguments() {
- return 2;
- }
- static get eval() {
- return 3;
- }
- static get arguments() {
- return 4;
- }
- };
-
- assertEquals(1, new C().eval);
- assertEquals(2, new C().arguments);
- assertEquals(3, C.eval);
- assertEquals(4, C.arguments);
-})();
-
-
-(function Setters() {
- var x = 0;
- class C {
- set eval(v) {
- x = v;
- }
- set arguments(v) {
- x = v;
- }
- static set eval(v) {
- x = v;
- }
- static set arguments(v) {
- x = v;
- }
- };
-
- new C().eval = 1;
- assertEquals(1, x);
- new C().arguments = 2;
- assertEquals(2, x);
- C.eval = 3;
- assertEquals(3, x);
- C.arguments = 4;
- assertEquals(4, x);
-})();
+++ /dev/null
-// 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-classes
-
-'use strict';
-(function TestArgumentsAccess() {
- class Base {
- constructor() {
- assertEquals(2, arguments.length);
- assertEquals(1, arguments[0]);
- assertEquals(2, arguments[1]);
- }
- }
-
- let b = new Base(1,2);
-
- class Subclass extends Base {
- constructor() {
- assertEquals(2, arguments.length);
- assertEquals(3, arguments[0]);
- assertEquals(4, arguments[1]);
- super(1,2);
- }
- }
-
- let s = new Subclass(3,4);
- assertEquals(0, Subclass.length);
-
- class Subclass2 extends Base {
- constructor(x,y) {
- assertEquals(2, arguments.length);
- assertEquals(3, arguments[0]);
- assertEquals(4, arguments[1]);
- super(1,2);
- }
- }
-
- let s2 = new Subclass2(3,4);
- assertEquals(2, Subclass2.length);
-}());
-
-(function TestThisAccessRestriction() {
- class Base {
- constructor(a, b) {
- let o = new Object();
- o.prp = a + b;
- return o;
- }
- }
-
- class Subclass extends Base {
- constructor(a, b) {
- var exn;
- try {
- this.prp1 = 3;
- } catch (e) {
- exn = e;
- }
- assertTrue(exn instanceof ReferenceError);
- super(a, b);
- assertSame(a + b, this.prp);
- assertSame(undefined, this.prp1);
- assertFalse(this.hasOwnProperty("prp1"));
- return this;
- }
- }
-
- let b = new Base(1, 2);
- assertSame(3, b.prp);
-
-
- let s = new Subclass(2, -1);
- assertSame(1, s.prp);
- assertSame(undefined, s.prp1);
- assertFalse(s.hasOwnProperty("prp1"));
-
- class Subclass2 extends Base {
- constructor(x) {
- super(1,2);
-
- if (x < 0) return;
-
- let called = false;
- function tmp() { called = true; return 3; }
- var exn = null;
- try {
- super(tmp(),4);
- } catch (e) { exn = e; }
- assertTrue(exn instanceof ReferenceError);
- assertTrue(called);
- }
- }
-
- var s2 = new Subclass2(1);
- assertSame(3, s2.prp);
-
- var s3 = new Subclass2(-1);
- assertSame(3, s3.prp);
-
- assertThrows(function() { Subclass.call(new Object(), 1, 2); }, TypeError);
- assertThrows(function() { Base.call(new Object(), 1, 2); }, TypeError);
-
- class BadSubclass extends Base {
- constructor() {}
- }
-
- assertThrows(function() { new BadSubclass(); }, ReferenceError);
-}());
-
-(function TestThisCheckOrdering() {
- let baseCalled = 0;
- class Base {
- constructor() { baseCalled++ }
- }
-
- let fCalled = 0;
- function f() { fCalled++; return 3; }
-
- class Subclass1 extends Base {
- constructor() {
- baseCalled = 0;
- super();
- assertEquals(1, baseCalled);
- let obj = this;
-
- let exn = null;
- baseCalled = 0;
- fCalled = 0;
- try {
- super(f());
- } catch (e) { exn = e; }
- assertTrue(exn instanceof ReferenceError);
- assertEquals(1, fCalled);
- assertEquals(1, baseCalled);
- assertSame(obj, this);
-
- exn = null;
- baseCalled = 0;
- fCalled = 0;
- try {
- super(super(), f());
- } catch (e) { exn = e; }
- assertTrue(exn instanceof ReferenceError);
- assertEquals(0, fCalled);
- assertEquals(1, baseCalled);
- assertSame(obj, this);
-
- exn = null;
- baseCalled = 0;
- fCalled = 0;
- try {
- super(f(), super());
- } catch (e) { exn = e; }
- assertTrue(exn instanceof ReferenceError);
- assertEquals(1, fCalled);
- assertEquals(1, baseCalled);
- assertSame(obj, this);
- }
- }
-
- new Subclass1();
-}());
-
-
-(function TestPrototypeWiring() {
- class Base {
- constructor(x) {
- this.foobar = x;
- }
- }
-
- class Subclass extends Base {
- constructor(x) {
- super(x);
- }
- }
-
- let s = new Subclass(1);
- assertSame(1, s.foobar);
- assertSame(Subclass.prototype, s.__proto__);
-
- let s1 = new Subclass(1, 2);
- assertSame(1, s1.foobar);
- assertTrue(s1.__proto__ === Subclass.prototype);
-
- let s2 = new Subclass();
- assertSame(undefined, s2.foobar);
- assertSame(Subclass.prototype, s2.__proto__);
- assertThrows(function() { Subclass(1); }, TypeError);
- assertThrows(function() { Subclass(1,2,3,4); }, TypeError);
-
- class Subclass2 extends Subclass {
- constructor() {
- super(5, 6, 7);
- }
- }
-
- let ss2 = new Subclass2();
- assertSame(5, ss2.foobar);
- assertSame(Subclass2.prototype, ss2.__proto__);
-
- class Subclass3 extends Base {
- constructor(x,y) {
- super(x + y);
- }
- }
-
- let ss3 = new Subclass3(27,42-27);
- assertSame(42, ss3.foobar);
- assertSame(Subclass3.prototype, ss3.__proto__);
-}());
-
-(function TestSublclassingBuiltins() {
- class ExtendedUint8Array extends Uint8Array {
- constructor() {
- super(10);
- this[0] = 255;
- this[1] = 0xFFA;
- }
- }
-
- var eua = new ExtendedUint8Array();
- assertEquals(10, eua.length);
- assertEquals(10, eua.byteLength);
- assertEquals(0xFF, eua[0]);
- assertEquals(0xFA, eua[1]);
- assertSame(ExtendedUint8Array.prototype, eua.__proto__);
- assertEquals("[object Uint8Array]", Object.prototype.toString.call(eua));
-}());
-
-(function TestSubclassingNull() {
- let N = null;
-
- class Foo extends N {
- constructor(x,y) {
- assertSame(1, x);
- assertSame(2, y);
- return {};
- }
- }
-
- new Foo(1,2);
-}());
-
-(function TestSubclassBinding() {
- class Base {
- constructor(x, y) {
- this.x = x;
- this.y = y;
- }
- }
-
- let obj = {};
- class Subclass extends Base {
- constructor(x,y) {
- super(x,y);
- assertTrue(this !== obj);
- }
- }
-
- let f = Subclass.bind(obj);
- assertThrows(function () { f(1, 2); }, TypeError);
- let s = new f(1, 2);
- assertSame(1, s.x);
- assertSame(2, s.y);
- assertSame(Subclass.prototype, s.__proto__);
-
- let s1 = new f(1);
- assertSame(1, s1.x);
- assertSame(undefined, s1.y);
- assertSame(Subclass.prototype, s1.__proto__);
-
- let g = Subclass.bind(obj, 1);
- assertThrows(function () { g(8); }, TypeError);
- let s2 = new g(8);
- assertSame(1, s2.x);
- assertSame(8, s2.y);
- assertSame(Subclass.prototype, s.__proto__);
-}());
-
-
-(function TestDefaultConstructor() {
- class Base1 { }
- assertThrows(function() { Base1(); }, TypeError);
-
- class Subclass1 extends Base1 { }
-
- assertThrows(function() { Subclass1(); }, TypeError);
-
- let s1 = new Subclass1();
- assertSame(s1.__proto__, Subclass1.prototype);
-
- class Base2 {
- constructor(x, y) {
- this.x = x;
- this.y = y;
- }
- }
-
- class Subclass2 extends Base2 {};
-
- let s2 = new Subclass2(1, 2);
-
- assertSame(s2.__proto__, Subclass2.prototype);
- assertSame(1, s2.x);
- assertSame(2, s2.y);
-
- let f = Subclass2.bind({}, 3, 4);
- let s2prime = new f();
- assertSame(s2prime.__proto__, Subclass2.prototype);
- assertSame(3, s2prime.x);
- assertSame(4, s2prime.y);
-
- let obj = {};
- class Base3 {
- constructor() {
- return obj;
- }
- }
-
- class Subclass3 extends Base3 {};
-
- let s3 = new Subclass3();
- assertSame(obj, s3);
-
- class ExtendedUint8Array extends Uint8Array { }
-
- var eua = new ExtendedUint8Array(10);
- assertEquals(10, eua.length);
- assertEquals(10, eua.byteLength);
- eua[0] = 0xFF;
- eua[1] = 0xFFA;
- assertEquals(0xFF, eua[0]);
- assertEquals(0xFA, eua[1]);
- assertSame(ExtendedUint8Array.prototype, eua.__proto__);
- assertEquals("[object Uint8Array]", Object.prototype.toString.call(eua));
-}());
+++ /dev/null
-// 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-classes --min-preparse-length=0
-
-'use strict';
-
-class Base {
- m() {
- return 42;
- }
-}
-
-class Derived extends Base {
- m() {
- return super.m();
- }
- evalM() {
- return eval('super.m()');
- }
-}
-
-assertEquals(42, new Derived().m());
-assertEquals(42, new Derived().evalM());
-
-
-class LazyDerived extends Base {
- constructor() {
- eval('super()');
- }
-}
-assertInstanceof(new LazyDerived(), LazyDerived);
-assertInstanceof(new LazyDerived(), Base);
+++ /dev/null
-// 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-classes --allow-natives-syntax
-'use strict';
-
-(function TestMaps() {
- class Base {}
- class Derived extends Base {}
-
- let d1 = new Derived();
- let d2 = new Derived();
-
- assertTrue(%HaveSameMap(d1, d2));
-}());
-
-
-(function TestProtoModificationArray() {
- let called = 0;
- function F() {
- called++;
- assertFalse(Array.isArray(this));
- }
- class Derived extends Array {}
- assertSame(Derived.__proto__, Array);
-
- let d1 = new Derived();
- assertTrue(Array.isArray(d1));
-
- Derived.__proto__ = F;
- called = 0;
- let d2 = new Derived();
- assertSame(1, called);
- assertFalse(Array.isArray(d2));
-
- assertFalse(%HaveSameMap(d1, d2));
-}());
-
-
-(function TestProtoModification() {
- let called = 0;
- function F() {
- called++;
- let exn = null;
- try {
- this.byteLength;
- } catch (e) {
- exn = e;
- }
- assertTrue(exn instanceof TypeError);
- }
- class Derived extends Uint8Array {
- constructor() { super(10); }
- }
- assertSame(Derived.__proto__, Uint8Array);
-
- let d1 = new Derived();
- assertSame(10, d1.byteLength);
-
- Derived.__proto__ = F;
- called = 0;
- let d2 = new Derived();
- assertSame(1, called);
- assertThrows(function() { d2.byteLength; }, TypeError);
-
- assertFalse(%HaveSameMap(d1, d2));
-}());
+++ /dev/null
-// Copyright 2015 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-classes
-'use strict';
-
-(function TestDefaultConstructor() {
- class Stack extends Array { }
- {
- let s1 = new Stack();
- assertSame(Stack.prototype, s1.__proto__);
- assertTrue(Array.isArray(s1));
- assertSame(0, s1.length);
- s1[0] = 'xyz';
- assertSame(1, s1.length);
- assertSame('xyz', s1[0]);
- s1.push(42);
- assertSame(2, s1.length);
- assertSame('xyz', s1[0]);
- assertSame(42, s1[1]);
- }
-
- {
- let s2 = new Stack(10);
- assertSame(Stack.prototype, s2.__proto__);
- assertTrue(Array.isArray(s2));
- assertSame(10, s2.length);
- assertSame(undefined, s2[0]);
- }
-
- {
- let a = [1,2,3];
- let s3 = new Stack(a);
- assertSame(Stack.prototype, s3.__proto__);
- assertTrue(Array.isArray(s3));
- assertSame(1, s3.length);
- assertSame(a, s3[0]);
- }
-
- {
- let s4 = new Stack(1, 2, 3);
- assertSame(Stack.prototype, s4.__proto__);
- assertTrue(Array.isArray(s4));
- assertSame(3, s4.length);
- assertSame(1, s4[0]);
- assertSame(2, s4[1]);
- assertSame(3, s4[2]);
- }
-
- {
- let s5 = new Stack(undefined, undefined, undefined);
- assertSame(Stack.prototype, s5.__proto__);
- assertTrue(Array.isArray(s5));
- assertSame(3, s5.length);
- assertSame(undefined, s5[0]);
- assertSame(undefined, s5[1]);
- assertSame(undefined, s5[2]);
- }
-}());
-
-
-(function TestEmptyArgsSuper() {
- class Stack extends Array {
- constructor() { super(); }
- }
- let s1 = new Stack();
- assertSame(Stack.prototype, s1.__proto__);
- assertTrue(Array.isArray(s1));
- assertSame(0, s1.length);
- s1[0] = 'xyz';
- assertSame(1, s1.length);
- assertSame('xyz', s1[0]);
- s1.push(42);
- assertSame(2, s1.length);
- assertSame('xyz', s1[0]);
- assertSame(42, s1[1]);
-}());
-
-
-(function TestOneArgSuper() {
- class Stack extends Array {
- constructor(x) {
- super(x);
- }
- }
-
- {
- let s2 = new Stack(10, 'ignored arg');
- assertSame(Stack.prototype, s2.__proto__);
- assertTrue(Array.isArray(s2));
- assertSame(10, s2.length);
- assertSame(undefined, s2[0]);
- }
-
- {
- let a = [1,2,3];
- let s3 = new Stack(a, 'ignored arg');
- assertSame(Stack.prototype, s3.__proto__);
- assertTrue(Array.isArray(s3));
- assertSame(1, s3.length);
- assertSame(a, s3[0]);
- }
-}());
-
-
-(function TestMultipleArgsSuper() {
- class Stack extends Array {
- constructor(x, y, z) {
- super(x, y, z);
- }
- }
- {
- let s4 = new Stack(1, 2, 3, 4, 5);
- assertSame(Stack.prototype, s4.__proto__);
- assertTrue(Array.isArray(s4));
- assertSame(3, s4.length);
- assertSame(1, s4[0]);
- assertSame(2, s4[1]);
- assertSame(3, s4[2]);
- }
-
- {
- let s5 = new Stack(undefined);
- assertSame(Stack.prototype, s5.__proto__);
- assertTrue(Array.isArray(s5));
- assertTrue(s5.__proto__ == Stack.prototype);
- assertSame(3, s5.length);
- assertSame(undefined, s5[0]);
- assertSame(undefined, s5[1]);
- assertSame(undefined, s5[2]);
- }
-}());
-
-
-(function TestArrayConcat() {
- class Stack extends Array { }
- let s1 = new Stack(1,2,3);
-
- assertArrayEquals([1,2,3,4,5,6], s1.concat([4,5,6]));
- assertArrayEquals([4,5,6,1,2,3], [4,5,6].concat(s1));
-}());
-
-
-(function TestJSONStringify() {
- class Stack extends Array { }
-
- let s1 = new Stack(1,2,3);
- assertSame("[1,2,3]", JSON.stringify(s1));
-}());
+++ /dev/null
-// 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-classes --harmony-sloppy
-
-(function TestBasics() {
- var C = class C {}
- assertEquals(typeof C, 'function');
- assertEquals(C.__proto__, Function.prototype);
- assertEquals(Object.prototype, Object.getPrototypeOf(C.prototype));
- assertEquals(Function.prototype, Object.getPrototypeOf(C));
- assertEquals('C', C.name);
-
- class D {}
- assertEquals(typeof D, 'function');
- assertEquals(D.__proto__, Function.prototype);
- assertEquals(Object.prototype, Object.getPrototypeOf(D.prototype));
- assertEquals(Function.prototype, Object.getPrototypeOf(D));
- assertEquals('D', D.name);
-
- class D2 { constructor() {} }
- assertEquals('D2', D2.name);
-
- // TODO(arv): The logic for the name of anonymous functions in ES6 requires
- // the below to be 'E';
- var E = class {}
- assertEquals('', E.name); // Should be 'E'.
-
- var F = class { constructor() {} };
- assertEquals('', F.name); // Should be 'F'.
-})();
-
-
-(function TestBasicsExtends() {
- class C extends null {}
- assertEquals(typeof C, 'function');
- assertEquals(C.__proto__, Function.prototype);
- assertEquals(null, Object.getPrototypeOf(C.prototype));
-
- class D extends C {}
- assertEquals(typeof D, 'function');
- assertEquals(D.__proto__, C);
- assertEquals(C.prototype, Object.getPrototypeOf(D.prototype));
-})();
-
-
-(function TestSideEffectInExtends() {
- var calls = 0;
- class C {}
- class D extends (calls++, C) {}
- assertEquals(1, calls);
- assertEquals(typeof D, 'function');
- assertEquals(D.__proto__, C);
- assertEquals(C.prototype, Object.getPrototypeOf(D.prototype));
-})();
-
-
-(function TestInvalidExtends() {
- assertThrows(function() {
- class C extends 42 {}
- }, TypeError);
-
- assertThrows(function() {
- // Function but its .prototype is not null or a function.
- class C extends Math.abs {}
- }, TypeError);
-
- assertThrows(function() {
- Math.abs.prototype = 42;
- class C extends Math.abs {}
- }, TypeError);
- delete Math.abs.prototype;
-
- assertThrows(function() {
- function* g() {}
- class C extends g {}
- }, TypeError);
-})();
-
-
-(function TestConstructorProperty() {
- class C {}
- assertEquals(C, C.prototype.constructor);
- var descr = Object.getOwnPropertyDescriptor(C.prototype, 'constructor');
- assertTrue(descr.configurable);
- assertFalse(descr.enumerable);
- assertTrue(descr.writable);
-})();
-
-
-(function TestPrototypeProperty() {
- class C {}
- var descr = Object.getOwnPropertyDescriptor(C, 'prototype');
- assertFalse(descr.configurable);
- assertFalse(descr.enumerable);
- assertFalse(descr.writable);
-})();
-
-
-(function TestConstructor() {
- var count = 0;
- class C {
- constructor() {
- assertEquals(Object.getPrototypeOf(this), C.prototype);
- count++;
- }
- }
- assertEquals(C, C.prototype.constructor);
- var descr = Object.getOwnPropertyDescriptor(C.prototype, 'constructor');
- assertTrue(descr.configurable);
- assertFalse(descr.enumerable);
- assertTrue(descr.writable);
-
- var c = new C();
- assertEquals(1, count);
- assertEquals(Object.getPrototypeOf(c), C.prototype);
-})();
-
-
-(function TestImplicitConstructor() {
- class C {}
- var c = new C();
- assertEquals(Object.getPrototypeOf(c), C.prototype);
-})();
-
-
-(function TestConstructorStrict() {
- class C {
- constructor() {
- assertThrows(function() {
- nonExistingBinding = 42;
- }, ReferenceError);
- }
- }
- new C();
-})();
-
-
-(function TestSuperInConstructor() {
- var calls = 0;
- class B {}
- B.prototype.x = 42;
-
- class C extends B {
- constructor() {
- super();
- calls++;
- assertEquals(42, super.x);
- }
- }
-
- new C;
- assertEquals(1, calls);
-})();
-
-
-(function TestStrictMode() {
- class C {}
-
- with ({a: 1}) {
- assertEquals(1, a);
- }
-
- assertThrows('class C extends function B() { with ({}); return B; }() {}',
- SyntaxError);
-
- var D = class extends function() {
- arguments.caller;
- } {};
- assertThrows(function() {
- Object.getPrototypeOf(D).arguments;
- }, TypeError);
- assertThrows(function() {
- new D;
- }, TypeError);
-})();
-
-
-(function TestToString() {
- class C {}
- assertEquals('class C {}', C.toString());
-
- class D { constructor() { 42; } }
- assertEquals('class D { constructor() { 42; } }', D.toString());
-
- class E { x() { 42; } }
- assertEquals('class E { x() { 42; } }', E.toString());
-})();
-
-
-function assertMethodDescriptor(object, name) {
- var descr = Object.getOwnPropertyDescriptor(object, name);
- assertTrue(descr.configurable);
- assertFalse(descr.enumerable);
- assertTrue(descr.writable);
- assertEquals('function', typeof descr.value);
- assertFalse('prototype' in descr.value);
-}
-
-
-function assertGetterDescriptor(object, name) {
- var descr = Object.getOwnPropertyDescriptor(object, name);
- assertTrue(descr.configurable);
- assertFalse(descr.enumerable);
- assertEquals('function', typeof descr.get);
- assertFalse('prototype' in descr.get);
- assertEquals(undefined, descr.set);
-}
-
-
-function assertSetterDescriptor(object, name) {
- var descr = Object.getOwnPropertyDescriptor(object, name);
- assertTrue(descr.configurable);
- assertFalse(descr.enumerable);
- assertEquals(undefined, descr.get);
- assertEquals('function', typeof descr.set);
- assertFalse('prototype' in descr.set);
-}
-
-
-function assertAccessorDescriptor(object, name) {
- var descr = Object.getOwnPropertyDescriptor(object, name);
- assertTrue(descr.configurable);
- assertFalse(descr.enumerable);
- assertEquals('function', typeof descr.get);
- assertEquals('function', typeof descr.set);
- assertFalse('prototype' in descr.get);
- assertFalse('prototype' in descr.set);
-}
-
-
-(function TestMethods() {
- class C {
- method() { return 1; }
- static staticMethod() { return 2; }
- method2() { return 3; }
- static staticMethod2() { return 4; }
- }
-
- assertMethodDescriptor(C.prototype, 'method');
- assertMethodDescriptor(C.prototype, 'method2');
- assertMethodDescriptor(C, 'staticMethod');
- assertMethodDescriptor(C, 'staticMethod2');
-
- assertEquals(1, new C().method());
- assertEquals(2, C.staticMethod());
- assertEquals(3, new C().method2());
- assertEquals(4, C.staticMethod2());
-})();
-
-
-(function TestGetters() {
- class C {
- get x() { return 1; }
- static get staticX() { return 2; }
- get y() { return 3; }
- static get staticY() { return 4; }
- }
-
- assertGetterDescriptor(C.prototype, 'x');
- assertGetterDescriptor(C.prototype, 'y');
- assertGetterDescriptor(C, 'staticX');
- assertGetterDescriptor(C, 'staticY');
-
- assertEquals(1, new C().x);
- assertEquals(2, C.staticX);
- assertEquals(3, new C().y);
- assertEquals(4, C.staticY);
-})();
-
-
-
-(function TestSetters() {
- var x, staticX, y, staticY;
- class C {
- set x(v) { x = v; }
- static set staticX(v) { staticX = v; }
- set y(v) { y = v; }
- static set staticY(v) { staticY = v; }
- }
-
- assertSetterDescriptor(C.prototype, 'x');
- assertSetterDescriptor(C.prototype, 'y');
- assertSetterDescriptor(C, 'staticX');
- assertSetterDescriptor(C, 'staticY');
-
- assertEquals(1, new C().x = 1);
- assertEquals(1, x);
- assertEquals(2, C.staticX = 2);
- assertEquals(2, staticX);
- assertEquals(3, new C().y = 3);
- assertEquals(3, y);
- assertEquals(4, C.staticY = 4);
- assertEquals(4, staticY);
-})();
-
-
-(function TestSideEffectsInPropertyDefine() {
- function B() {}
- B.prototype = {
- constructor: B,
- set m(v) {
- throw Error();
- }
- };
-
- class C extends B {
- m() { return 1; }
- }
-
- assertEquals(1, new C().m());
-})();
-
-
-(function TestAccessors() {
- class C {
- constructor(x) {
- this._x = x;
- }
-
- get x() { return this._x; }
- set x(v) { this._x = v; }
-
- static get staticX() { return this._x; }
- static set staticX(v) { this._x = v; }
- }
-
- assertAccessorDescriptor(C.prototype, 'x');
- assertAccessorDescriptor(C, 'staticX');
-
- var c = new C(1);
- c._x = 1;
- assertEquals(1, c.x);
- c.x = 2;
- assertEquals(2, c._x);
-
- C._x = 3;
- assertEquals(3, C.staticX);
- C._x = 4;
- assertEquals(4, C.staticX );
-})();
-
-
-(function TestProto() {
- class C {
- __proto__() { return 1; }
- }
- assertMethodDescriptor(C.prototype, '__proto__');
- assertEquals(1, new C().__proto__());
-})();
-
-
-(function TestProtoStatic() {
- class C {
- static __proto__() { return 1; }
- }
- assertMethodDescriptor(C, '__proto__');
- assertEquals(1, C.__proto__());
-})();
-
-
-(function TestProtoAccessor() {
- class C {
- get __proto__() { return this._p; }
- set __proto__(v) { this._p = v; }
- }
- assertAccessorDescriptor(C.prototype, '__proto__');
- var c = new C();
- c._p = 1;
- assertEquals(1, c.__proto__);
- c.__proto__ = 2;
- assertEquals(2, c.__proto__);
-})();
-
-
-(function TestStaticProtoAccessor() {
- class C {
- static get __proto__() { return this._p; }
- static set __proto__(v) { this._p = v; }
- }
- assertAccessorDescriptor(C, '__proto__');
- C._p = 1;
- assertEquals(1, C.__proto__);
- C.__proto__ = 2;
- assertEquals(2, C.__proto__);
-})();
-
-
-(function TestSettersOnProto() {
- function Base() {}
- Base.prototype = {
- set constructor(_) {
- assertUnreachable();
- },
- set m(_) {
- assertUnreachable();
- }
- };
- Object.defineProperty(Base, 'staticM', {
- set: function() {
- assertUnreachable();
- }
- });
-
- class C extends Base {
- m() {
- return 1;
- }
- static staticM() {
- return 2;
- }
- }
-
- assertEquals(1, new C().m());
- assertEquals(2, C.staticM());
-})();
-
-
-(function TestConstructableButNoPrototype() {
- var Base = function() {}.bind();
- assertThrows(function() {
- class C extends Base {}
- }, TypeError);
-})();
-
-
-(function TestPrototypeGetter() {
- var calls = 0;
- var Base = function() {}.bind();
- Object.defineProperty(Base, 'prototype', {
- get: function() {
- calls++;
- return null;
- },
- configurable: true
- });
- class C extends Base {}
- assertEquals(1, calls);
-
- calls = 0;
- Object.defineProperty(Base, 'prototype', {
- get: function() {
- calls++;
- return 42;
- },
- configurable: true
- });
- assertThrows(function() {
- class C extends Base {}
- }, TypeError);
- assertEquals(1, calls);
-})();
-
-
-(function TestPrototypeSetter() {
- var Base = function() {}.bind();
- Object.defineProperty(Base, 'prototype', {
- set: function() {
- assertUnreachable();
- }
- });
- assertThrows(function() {
- class C extends Base {}
- }, TypeError);
-})();
-
-
-(function TestSuperInMethods() {
- class B {
- method() {
- return 1;
- }
- get x() {
- return 2;
- }
- }
- class C extends B {
- method() {
- assertEquals(2, super.x);
- return super.method();
- }
- }
- assertEquals(1, new C().method());
-})();
-
-
-(function TestSuperInGetter() {
- class B {
- method() {
- return 1;
- }
- get x() {
- return 2;
- }
- }
- class C extends B {
- get y() {
- assertEquals(2, super.x);
- return super.method();
- }
- }
- assertEquals(1, new C().y);
-})();
-
-
-(function TestSuperInSetter() {
- class B {
- method() {
- return 1;
- }
- get x() {
- return 2;
- }
- }
- class C extends B {
- set y(v) {
- assertEquals(3, v);
- assertEquals(2, super.x);
- assertEquals(1, super.method());
- }
- }
- assertEquals(3, new C().y = 3);
-})();
-
-
-(function TestSuperInStaticMethods() {
- class B {
- static method() {
- return 1;
- }
- static get x() {
- return 2;
- }
- }
- class C extends B {
- static method() {
- assertEquals(2, super.x);
- return super.method();
- }
- }
- assertEquals(1, C.method());
-})();
-
-
-(function TestSuperInStaticGetter() {
- class B {
- static method() {
- return 1;
- }
- static get x() {
- return 2;
- }
- }
- class C extends B {
- static get x() {
- assertEquals(2, super.x);
- return super.method();
- }
- }
- assertEquals(1, C.x);
-})();
-
-
-(function TestSuperInStaticSetter() {
- class B {
- static method() {
- return 1;
- }
- static get x() {
- return 2;
- }
- }
- class C extends B {
- static set x(v) {
- assertEquals(3, v);
- assertEquals(2, super.x);
- assertEquals(1, super.method());
- }
- }
- assertEquals(3, C.x = 3);
-})();
-
-
-(function TestNumericPropertyNames() {
- class B {
- 1() { return 1; }
- get 2() { return 2; }
- set 3(_) {}
-
- static 4() { return 4; }
- static get 5() { return 5; }
- static set 6(_) {}
- }
-
- assertMethodDescriptor(B.prototype, '1');
- assertGetterDescriptor(B.prototype, '2');
- assertSetterDescriptor(B.prototype, '3');
-
- assertMethodDescriptor(B, '4');
- assertGetterDescriptor(B, '5');
- assertSetterDescriptor(B, '6');
-
- class C extends B {
- 1() { return super[1](); }
- get 2() { return super[2]; }
-
- static 4() { return super[4](); }
- static get 5() { return super[5]; }
- }
-
- assertEquals(1, new C()[1]());
- assertEquals(2, new C()[2]);
- assertEquals(4, C[4]());
- assertEquals(5, C[5]);
-})();
-
-
-(function TestDefaultConstructorNoCrash() {
- // Regression test for https://code.google.com/p/v8/issues/detail?id=3661
- class C {}
- assertThrows(function () {C();}, TypeError);
- assertThrows(function () {C(1);}, TypeError);
- assertTrue(new C() instanceof C);
- assertTrue(new C(1) instanceof C);
-})();
-
-
-(function TestDefaultConstructor() {
- var calls = 0;
- class Base {
- constructor() {
- calls++;
- }
- }
- class Derived extends Base {}
- var object = new Derived;
- assertEquals(1, calls);
-
- calls = 0;
- assertThrows(function() { Derived(); }, TypeError);
- assertEquals(0, calls);
-})();
-
-
-(function TestDefaultConstructorArguments() {
- var args, self;
- class Base {
- constructor() {
- self = this;
- args = arguments;
- }
- }
- class Derived extends Base {}
-
- new Derived;
- assertEquals(0, args.length);
-
- new Derived(0, 1, 2);
- assertEquals(3, args.length);
- assertTrue(self instanceof Derived);
-
- var arr = new Array(100);
- var obj = {};
- assertThrows(function() {Derived.apply(obj, arr);}, TypeError);
-})();
-
-
-(function TestDefaultConstructorArguments2() {
- var args;
- class Base {
- constructor(x, y) {
- args = arguments;
- }
- }
- class Derived extends Base {}
-
- new Derived;
- assertEquals(0, args.length);
-
- new Derived(1);
- assertEquals(1, args.length);
- assertEquals(1, args[0]);
-
- new Derived(1, 2, 3);
- assertEquals(3, args.length);
- assertEquals(1, args[0]);
- assertEquals(2, args[1]);
- assertEquals(3, args[2]);
-})();
-
-
-(function TestNameBindingConst() {
- assertThrows('class C { constructor() { C = 42; } }; new C();', TypeError);
- assertThrows('new (class C { constructor() { C = 42; } })', TypeError);
- assertThrows('class C { m() { C = 42; } }; new C().m()', TypeError);
- assertThrows('new (class C { m() { C = 42; } }).m()', TypeError);
- assertThrows('class C { get x() { C = 42; } }; new C().x', TypeError);
- assertThrows('(new (class C { get x() { C = 42; } })).x', TypeError);
- assertThrows('class C { set x(_) { C = 42; } }; new C().x = 15;', TypeError);
- assertThrows('(new (class C { set x(_) { C = 42; } })).x = 15;', TypeError);
-})();
-
-
-(function TestNameBinding() {
- var C2;
- class C {
- constructor() {
- C2 = C;
- }
- m() {
- C2 = C;
- }
- get x() {
- C2 = C;
- }
- set x(_) {
- C2 = C;
- }
- }
- new C();
- assertEquals(C, C2);
-
- C2 = undefined;
- new C().m();
- assertEquals(C, C2);
-
- C2 = undefined;
- new C().x;
- assertEquals(C, C2);
-
- C2 = undefined;
- new C().x = 1;
- assertEquals(C, C2);
-})();
-
-
-(function TestNameBindingExpression() {
- var C3;
- var C = class C2 {
- constructor() {
- assertEquals(C2, C);
- C3 = C2;
- }
- m() {
- assertEquals(C2, C);
- C3 = C2;
- }
- get x() {
- assertEquals(C2, C);
- C3 = C2;
- }
- set x(_) {
- assertEquals(C2, C);
- C3 = C2;
- }
- }
- new C();
- assertEquals(C, C3);
-
- C3 = undefined;
- new C().m();
- assertEquals(C, C3);
-
- C3 = undefined;
- new C().x;
- assertEquals(C, C3);
-
- C3 = undefined;
- new C().x = 1;
- assertEquals(C, C3);
-})();
-
-
-(function TestNameBindingInExtendsExpression() {
- assertThrows(function() {
- class x extends x {}
- }, ReferenceError);
-
- assertThrows(function() {
- (class x extends x {});
- }, ReferenceError);
-
- assertThrows(function() {
- var x = (class x extends x {});
- }, ReferenceError);
-})();
-
-
-(function TestThisAccessRestriction() {
- class Base {}
- (function() {
- class C extends Base {
- constructor() {
- var y;
- super();
- }
- }; new C();
- }());
- assertThrows(function() {
- class C extends Base {
- constructor() {
- super(this.x);
- }
- }; new C();
- }, ReferenceError);
- assertThrows(function() {
- class C extends Base {
- constructor() {
- super(this);
- }
- }; new C();
- }, ReferenceError);
- assertThrows(function() {
- class C extends Base {
- constructor() {
- super.method();
- super(this);
- }
- }; new C();
- }, ReferenceError);
- assertThrows(function() {
- class C extends Base {
- constructor() {
- super(super.method());
- }
- }; new C();
- }, ReferenceError);
- assertThrows(function() {
- class C extends Base {
- constructor() {
- super(super());
- }
- }; new C();
- }, ReferenceError);
- assertThrows(function() {
- class C extends Base {
- constructor() {
- super(1, 2, Object.getPrototypeOf(this));
- }
- }; new C();
- }, ReferenceError);
- (function() {
- class C extends Base {
- constructor() {
- { super(1, 2); }
- }
- }; new C();
- }());
- (function() {
- class C extends Base {
- constructor() {
- if (1) super();
- }
- }; new C();
- }());
-
- class C1 extends Object {
- constructor() {
- 'use strict';
- super();
- }
- };
- new C1();
-
- class C2 extends Object {
- constructor() {
- ; 'use strict';;;;;
- super();
- }
- };
- new C2();
-
- class C3 extends Object {
- constructor() {
- ; 'use strict';;;;;
- // This is a comment.
- super();
- }
- };
- new C3();
-}());
-
-
-function testClassRestrictedProperties(C) {
- assertEquals(false, C.hasOwnProperty("arguments"));
- assertThrows(function() { return C.arguments; }, TypeError);
- assertThrows(function() { C.arguments = {}; }, TypeError);
-
- assertEquals(false, C.hasOwnProperty("caller"));
- assertThrows(function() { return C.caller; }, TypeError);
- assertThrows(function() { C.caller = {}; }, TypeError);
-
- assertEquals(false, (new C).method.hasOwnProperty("arguments"));
- assertThrows(function() { return new C().method.arguments; }, TypeError);
- assertThrows(function() { new C().method.arguments = {}; }, TypeError);
-
- assertEquals(false, (new C).method.hasOwnProperty("caller"));
- assertThrows(function() { return new C().method.caller; }, TypeError);
- assertThrows(function() { new C().method.caller = {}; }, TypeError);
-}
-
-
-(function testRestrictedPropertiesStrict() {
- "use strict";
- class ClassWithDefaultConstructor {
- method() {}
- }
- class Class {
- constructor() {}
- method() {}
- }
- class DerivedClassWithDefaultConstructor extends Class {}
- class DerivedClass extends Class { constructor() { super(); } }
-
- testClassRestrictedProperties(ClassWithDefaultConstructor);
- testClassRestrictedProperties(Class);
- testClassRestrictedProperties(DerivedClassWithDefaultConstructor);
- testClassRestrictedProperties(DerivedClass);
- testClassRestrictedProperties(class { method() {} });
- testClassRestrictedProperties(class { constructor() {} method() {} });
- testClassRestrictedProperties(class extends Class { });
- testClassRestrictedProperties(
- class extends Class { constructor() { super(); } });
-})();
-
-
-(function testRestrictedPropertiesSloppy() {
- class ClassWithDefaultConstructor {
- method() {}
- }
- class Class {
- constructor() {}
- method() {}
- }
- class DerivedClassWithDefaultConstructor extends Class {}
- class DerivedClass extends Class { constructor() { super(); } }
-
- testClassRestrictedProperties(ClassWithDefaultConstructor);
- testClassRestrictedProperties(Class);
- testClassRestrictedProperties(DerivedClassWithDefaultConstructor);
- testClassRestrictedProperties(DerivedClass);
- testClassRestrictedProperties(class { method() {} });
- testClassRestrictedProperties(class { constructor() {} method() {} });
- testClassRestrictedProperties(class extends Class { });
- testClassRestrictedProperties(
- class extends Class { constructor() { super(); } });
-})();
'use strict';
-// Flags: --harmony-computed-property-names --harmony-classes
+// Flags: --harmony-computed-property-names
function ID(x) {
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Flags: --harmony-computed-property-names
-// Flags: --harmony-classes --allow-natives-syntax
+// Flags: --harmony-computed-property-names --allow-natives-syntax
function ID(x) {
+++ /dev/null
-// 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: --expose-debug-as debug --harmony-classes
-
-'use strict';
-
-var Debug = debug.Debug
-
-var done = false;
-var stepCount = 0;
-
-function listener(event, execState, eventData, data) {
- if (event == Debug.DebugEvent.Break) {
- if (!done) {
- execState.prepareStep(Debug.StepAction.StepInto);
- var s = execState.frame().sourceLineText();
- assertTrue(s.indexOf('// ' + stepCount + '.') !== -1);
- stepCount++;
- }
- }
-};
-
-Debug.setListener(listener);
-
-function GetBase() {
- var x = 1; // 1.
- var y = 2; // 2.
- done = true; // 3.
- return null;
-}
-
-function f() {
- class Derived extends GetBase() {} // 0.
-}
-
-var bp = Debug.setBreakPoint(f, 0);
-f();
-assertEquals(4, stepCount);
-
-Debug.setListener(null);
+++ /dev/null
-// 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: --expose-debug-as debug --harmony-classes
-
-'use strict';
-
-var Debug = debug.Debug
-var done, stepCount;
-
-function listener(event, execState, eventData, data) {
- if (event == Debug.DebugEvent.Break) {
- if (!done) {
- execState.prepareStep(Debug.StepAction.StepInto);
- var s = execState.frame().sourceLineText();
- assertTrue(s.indexOf('// ' + stepCount + '.') !== -1);
- stepCount++;
- }
- }
-};
-
-Debug.setListener(listener);
-
-
-class Base {
- constructor() {
- var x = 1; // 1.
- var y = 2; // 2.
- done = true; // 3.
- }
-}
-
-class Derived extends Base {}
-
-
-(function TestBreakPointInConstructor() {
- done = false;
- stepCount = 1;
- var bp = Debug.setBreakPoint(Base, 0);
-
- new Base();
- assertEquals(4, stepCount);
-
- Debug.clearBreakPoint(bp);
-})();
-
-
-(function TestDefaultConstructor() {
- done = false;
- stepCount = 1;
-
- var bp = Debug.setBreakPoint(Base, 0);
- new Derived();
- assertEquals(4, stepCount);
-
- Debug.clearBreakPoint(bp);
-})();
-
-
-(function TestStepInto() {
- done = false;
- stepCount = 0;
-
- function f() {
- new Derived(); // 0.
- }
-
- var bp = Debug.setBreakPoint(f, 0);
- f();
- assertEquals(4, stepCount);
-
- Debug.clearBreakPoint(bp);
-})();
-
-
-(function TestExtraIndirection() {
- done = false;
- stepCount = 0;
-
- class Derived2 extends Derived {}
-
- function f() {
- new Derived2(); // 0.
- }
-
- var bp = Debug.setBreakPoint(f, 0);
- f();
- assertEquals(4, stepCount);
-
- Debug.clearBreakPoint(bp);
-})();
-
-
-(function TestBoundClass() {
- done = false;
- stepCount = 0;
-
- var bound = Derived.bind(null);
-
- function f() {
- new bound(); // 0.
- }
-
- var bp = Debug.setBreakPoint(f, 0);
- f();
- assertEquals(4, stepCount);
-
- Debug.clearBreakPoint(bp);
-})();
-
-
-Debug.setListener(null);
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Flags: --harmony-classes --harmony-arrow-functions --allow-natives-syntax
+// Flags: --harmony-arrow-functions --allow-natives-syntax
(function TestHomeObject() {
+++ /dev/null
-// 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-classes
-'use strict';
-class Example { }
-Object.observe(Example.prototype, function(){});
+++ /dev/null
-// Copyright 2015 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-classes --no-lazy
-"use strict";
-class Base {
-}
-class Subclass extends Base {
- constructor() {
- this.prp1 = 3;
- }
-}
-function __f_1(){
-}
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Flags: --harmony-computed-property-names --harmony-classes --harmony-sloppy
+// Flags: --harmony-computed-property-names --harmony-sloppy
assertThrows(function f() {
var t = { toString: function() { throw new Error(); } };
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Flags: --harmony-rest-parameters --harmony-classes
+// Flags: --harmony-rest-parameters
(function testRestIndex() {
assertEquals(5, (function(...args) { return args.length; })(1,2,3,4,5));
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Flags: --harmony-classes --harmony-arrow-functions --allow-natives-syntax
+// Flags: --harmony-arrow-functions --allow-natives-syntax
// Flags: --harmony-spreadcalls
(function TestSuperNamedLoads() {
+++ /dev/null
-// 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-classes --allow-natives-syntax
-
-
-(function TestSingleClass() {
- function f(x) {
- var a = [0, 1, 2]
- return a[x];
- }
-
- function ClassD() { }
-
- assertEquals(1, f(1));
- var g = %ToMethod(f, ClassD.prototype);
- assertEquals(1, g(1));
- assertEquals(undefined, f[%HomeObjectSymbol()]);
- assertEquals(ClassD.prototype, g[%HomeObjectSymbol()]);
-}());
-
-
-(function TestClassHierarchy() {
- function f(x) {
- return function g(y) { x++; return x + y; };
- }
-
- function Base() {}
- function Derived() { }
- Derived.prototype = Object.create(Base.prototype);
-
- var q = f(0);
- assertEquals(2, q(1));
- assertEquals(3, q(1));
- var g = %ToMethod(q, Derived.prototype);
- assertFalse(g === q);
- assertEquals(4, g(1));
- assertEquals(5, q(1));
-}());
-
-
-(function TestPrototypeChain() {
- var o = {};
- var o1 = {};
- function f() { }
-
- function g() { }
-
- var fMeth = %ToMethod(f, o);
- assertEquals(o, fMeth[%HomeObjectSymbol()]);
- g.__proto__ = fMeth;
- assertEquals(undefined, g[%HomeObjectSymbol()]);
- var gMeth = %ToMethod(g, o1);
- assertEquals(fMeth, gMeth.__proto__);
- assertEquals(o, fMeth[%HomeObjectSymbol()]);
- assertEquals(o1, gMeth[%HomeObjectSymbol()]);
-}());
-
-
-(function TestBoundFunction() {
- var o = {};
- var p = {};
-
-
- function f(x, y, z, w) {
- assertEquals(o, this);
- assertEquals(1, x);
- assertEquals(2, y);
- assertEquals(3, z);
- assertEquals(4, w);
- return x+y+z+w;
- }
-
- var fBound = f.bind(o, 1, 2, 3);
- var fMeth = %ToMethod(fBound, p);
- assertEquals(10, fMeth(4));
- assertEquals(10, fMeth.call(p, 4));
- var fBound1 = fBound.bind(o, 4);
- assertEquals(10, fBound1());
- var fMethBound = fMeth.bind(o, 4);
- assertEquals(10, fMethBound());
-}());
-
-(function TestOptimized() {
- function f(o) {
- return o.x;
- }
- var o = {x : 15};
- assertEquals(15, f(o));
- assertEquals(15, f(o));
- %OptimizeFunctionOnNextCall(f);
- assertEquals(15, f(o));
- var g = %ToMethod(f, {});
- var o1 = {y : 1024, x : "abc"};
- assertEquals("abc", f(o1));
- assertEquals("abc", g(o1));
-} ());
-
-(function TestExtensibility() {
- function f() {}
- Object.preventExtensions(f);
- assertFalse(Object.isExtensible(f));
- var m = %ToMethod(f, {});
- assertTrue(Object.isExtensible(m));
-}());
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Flags: --strong-mode
-// Flags: --harmony-classes --harmony-arrow-functions
+// Flags: --strong-mode --harmony-arrow-functions
'use strong';
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Flags: --strong-mode --harmony_rest_parameters --harmony_arrow_functions --harmony_classes --harmony_computed-property_names
+// Flags: --strong-mode --harmony-rest-parameters --harmony-arrow-functions
+// Flags: --harmony-computed-property-names
// Note that it's essential for these tests that the reference is inside dead
// code (because we already produce ReferenceErrors for run-time unresolved
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Flags: --strong-mode --harmony-classes --allow-natives-syntax
+// Flags: --strong-mode --allow-natives-syntax
'use strong';