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

Side by Side Diff: test/cctest/test-func-name-inference.cc

Issue 1264603002: Add test for referring function name for classes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fixt typo Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/cctest.status ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 CHECK_NE(0, func_pos); 80 CHECK_NE(0, func_pos);
81 81
82 // Obtain SharedFunctionInfo for the function. 82 // Obtain SharedFunctionInfo for the function.
83 Handle<SharedFunctionInfo> shared_func_info = 83 Handle<SharedFunctionInfo> shared_func_info =
84 Handle<SharedFunctionInfo>::cast( 84 Handle<SharedFunctionInfo>::cast(
85 isolate->debug()->FindSharedFunctionInfoInScript(i_script, func_pos)); 85 isolate->debug()->FindSharedFunctionInfoInScript(i_script, func_pos));
86 86
87 // Verify inferred function name. 87 // Verify inferred function name.
88 SmartArrayPointer<char> inferred_name = 88 SmartArrayPointer<char> inferred_name =
89 shared_func_info->inferred_name()->ToCString(); 89 shared_func_info->inferred_name()->ToCString();
90 i::PrintF("expected: %s, found: %s\n", ref_inferred_name,
91 inferred_name.get());
90 CHECK_EQ(0, strcmp(ref_inferred_name, inferred_name.get())); 92 CHECK_EQ(0, strcmp(ref_inferred_name, inferred_name.get()));
91 } 93 }
92 94
93 95
94 static v8::Handle<v8::Script> Compile(v8::Isolate* isolate, const char* src) { 96 static v8::Handle<v8::Script> Compile(v8::Isolate* isolate, const char* src) {
95 return v8::Script::Compile(v8::String::NewFromUtf8(isolate, src)); 97 return v8::Script::Compile(v8::String::NewFromUtf8(isolate, src));
96 } 98 }
97 99
98 100
99 TEST(GlobalProperty) { 101 TEST(GlobalProperty) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 CcTest::isolate(), 217 CcTest::isolate(),
216 "function MyClass() {}\n" 218 "function MyClass() {}\n"
217 "MyClass.prototype = {\n" 219 "MyClass.prototype = {\n"
218 " method1: function() { return 1; },\n" 220 " method1: function() { return 1; },\n"
219 " method2: function() { return 2; } }"); 221 " method2: function() { return 2; } }");
220 CheckFunctionName(script, "return 1", "MyClass.method1"); 222 CheckFunctionName(script, "return 1", "MyClass.method1");
221 CheckFunctionName(script, "return 2", "MyClass.method2"); 223 CheckFunctionName(script, "return 2", "MyClass.method2");
222 } 224 }
223 225
224 226
227 TEST(UpperCaseClass) {
228 CcTest::InitializeVM();
229 v8::HandleScope scope(CcTest::isolate());
230
231 v8::Handle<v8::Script> script = Compile(CcTest::isolate(),
232 "'use strict';\n"
233 "class MyClass {\n"
234 " constructor() {\n"
235 " this.value = 1;\n"
236 " }\n"
237 " method() {\n"
238 " this.value = 2;\n"
239 " }\n"
240 "}");
241 CheckFunctionName(script, "this.value = 1", "MyClass");
242 CheckFunctionName(script, "this.value = 2", "MyClass.method");
243 }
244
245
246 TEST(LowerCaseClass) {
247 CcTest::InitializeVM();
248 v8::HandleScope scope(CcTest::isolate());
249
250 v8::Handle<v8::Script> script = Compile(CcTest::isolate(),
251 "'use strict';\n"
252 "class myclass {\n"
253 " constructor() {\n"
254 " this.value = 1;\n"
255 " }\n"
256 " method() {\n"
257 " this.value = 2;\n"
258 " }\n"
259 "}");
260 CheckFunctionName(script, "this.value = 1", "myclass");
261 CheckFunctionName(script, "this.value = 2", "myclass.method");
262 }
263
264
225 TEST(AsParameter) { 265 TEST(AsParameter) {
226 CcTest::InitializeVM(); 266 CcTest::InitializeVM();
227 v8::HandleScope scope(CcTest::isolate()); 267 v8::HandleScope scope(CcTest::isolate());
228 268
229 v8::Handle<v8::Script> script = Compile( 269 v8::Handle<v8::Script> script = Compile(
230 CcTest::isolate(), 270 CcTest::isolate(),
231 "function f1(a) { return a(); }\n" 271 "function f1(a) { return a(); }\n"
232 "function f2(a, b) { return a() + b(); }\n" 272 "function f2(a, b) { return a() + b(); }\n"
233 "var result1 = f1(function() { return 1; })\n" 273 "var result1 = f1(function() { return 1; })\n"
234 "var result2 = f2(function() { return 2; }, function() { return 3; })"); 274 "var result2 = f2(function() { return 2; }, function() { return 3; })");
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 " };\n" 536 " };\n"
497 " var foo = 10;\n" 537 " var foo = 10;\n"
498 " function f() {\n" 538 " function f() {\n"
499 " return wrapCode();\n" 539 " return wrapCode();\n"
500 " }\n" 540 " }\n"
501 " this.ref = f;\n" 541 " this.ref = f;\n"
502 "})()"); 542 "})()");
503 script->Run(); 543 script->Run();
504 CheckFunctionName(script, "return 2012", ""); 544 CheckFunctionName(script, "return 2012", "");
505 } 545 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698