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

Side by Side Diff: test/cctest/test-api.cc

Issue 26709011: Expose v8::Function::GetDisplayName to public API. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: fixed test Created 7 years, 1 month 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 | « src/api.cc ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 17486 matching lines...) Expand 10 before | Expand all | Expand 10 after
17497 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); 17497 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"));
17498 v8::Handle<v8::String> script = v8::String::New( 17498 v8::Handle<v8::String> script = v8::String::New(
17499 "var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;"); 17499 "var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;");
17500 v8::Script::Compile(script, &origin)->Run(); 17500 v8::Script::Compile(script, &origin)->Run();
17501 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 17501 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
17502 env->Global()->Get(v8::String::New("f"))); 17502 env->Global()->Get(v8::String::New("f")));
17503 CHECK_EQ("foo.bar.baz", *v8::String::Utf8Value(f->GetInferredName())); 17503 CHECK_EQ("foo.bar.baz", *v8::String::Utf8Value(f->GetInferredName()));
17504 } 17504 }
17505 17505
17506 17506
17507 THREADED_TEST(FunctionGetDisplayName) {
17508 LocalContext env;
17509 v8::HandleScope scope(env->GetIsolate());
17510 const char* code = "var error = false;"
17511 "function a() { this.x = 1; };"
17512 "a.displayName = 'display_a';"
17513 "var b = (function() {"
17514 " var f = function() { this.x = 2; };"
17515 " f.displayName = 'display_b';"
17516 " return f;"
17517 "})();"
17518 "var c = function() {};"
17519 "c.__defineGetter__('displayName', function() {"
17520 " error = true;"
17521 " throw new Error();"
17522 "});"
17523 "function d() {};"
17524 "d.__defineGetter__('displayName', function() {"
17525 " error = true;"
17526 " return 'wrong_display_name';"
17527 "});"
17528 "function e() {};"
17529 "e.displayName = 'wrong_display_name';"
17530 "e.__defineSetter__('displayName', function() {"
17531 " error = true;"
17532 " throw new Error();"
17533 "});"
17534 "function f() {};"
17535 "f.displayName = { 'foo': 6, toString: function() {"
17536 " error = true;"
17537 " return 'wrong_display_name';"
17538 "}};"
17539 "var g = function() {"
17540 " arguments.callee.displayName = 'set_in_runtime';"
17541 "}; g();"
17542 ;
17543 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"));
17544 v8::Script::Compile(v8::String::New(code), &origin)->Run();
17545 v8::Local<v8::Value> error = env->Global()->Get(v8::String::New("error"));
17546 v8::Local<v8::Function> a = v8::Local<v8::Function>::Cast(
17547 env->Global()->Get(v8::String::New("a")));
17548 v8::Local<v8::Function> b = v8::Local<v8::Function>::Cast(
17549 env->Global()->Get(v8::String::New("b")));
17550 v8::Local<v8::Function> c = v8::Local<v8::Function>::Cast(
17551 env->Global()->Get(v8::String::New("c")));
17552 v8::Local<v8::Function> d = v8::Local<v8::Function>::Cast(
17553 env->Global()->Get(v8::String::New("d")));
17554 v8::Local<v8::Function> e = v8::Local<v8::Function>::Cast(
17555 env->Global()->Get(v8::String::New("e")));
17556 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
17557 env->Global()->Get(v8::String::New("f")));
17558 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast(
17559 env->Global()->Get(v8::String::New("g")));
17560 CHECK_EQ(false, error->BooleanValue());
17561 CHECK_EQ("display_a", *v8::String::Utf8Value(a->GetDisplayName()));
17562 CHECK_EQ("display_b", *v8::String::Utf8Value(b->GetDisplayName()));
17563 CHECK(c->GetDisplayName()->IsUndefined());
17564 CHECK(d->GetDisplayName()->IsUndefined());
17565 CHECK(e->GetDisplayName()->IsUndefined());
17566 CHECK(f->GetDisplayName()->IsUndefined());
17567 CHECK_EQ("set_in_runtime", *v8::String::Utf8Value(g->GetDisplayName()));
17568 }
17569
17570
17507 THREADED_TEST(ScriptLineNumber) { 17571 THREADED_TEST(ScriptLineNumber) {
17508 LocalContext env; 17572 LocalContext env;
17509 v8::HandleScope scope(env->GetIsolate()); 17573 v8::HandleScope scope(env->GetIsolate());
17510 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); 17574 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"));
17511 v8::Handle<v8::String> script = v8::String::New( 17575 v8::Handle<v8::String> script = v8::String::New(
17512 "function f() {}\n\nfunction g() {}"); 17576 "function f() {}\n\nfunction g() {}");
17513 v8::Script::Compile(script, &origin)->Run(); 17577 v8::Script::Compile(script, &origin)->Run();
17514 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 17578 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
17515 env->Global()->Get(v8::String::New("f"))); 17579 env->Global()->Get(v8::String::New("f")));
17516 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( 17580 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast(
(...skipping 3130 matching lines...) Expand 10 before | Expand all | Expand 10 after
20647 } 20711 }
20648 for (int i = 0; i < runs; i++) { 20712 for (int i = 0; i < runs; i++) {
20649 Local<String> expected; 20713 Local<String> expected;
20650 if (i != 0) { 20714 if (i != 0) {
20651 CHECK_EQ(v8_str("escape value"), values[i]); 20715 CHECK_EQ(v8_str("escape value"), values[i]);
20652 } else { 20716 } else {
20653 CHECK(values[i].IsEmpty()); 20717 CHECK(values[i].IsEmpty());
20654 } 20718 }
20655 } 20719 }
20656 } 20720 }
OLDNEW
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698