OLD | NEW |
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 17393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17404 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); | 17404 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); |
17405 v8::Handle<v8::String> script = v8::String::New( | 17405 v8::Handle<v8::String> script = v8::String::New( |
17406 "var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;"); | 17406 "var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;"); |
17407 v8::Script::Compile(script, &origin)->Run(); | 17407 v8::Script::Compile(script, &origin)->Run(); |
17408 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( | 17408 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( |
17409 env->Global()->Get(v8::String::New("f"))); | 17409 env->Global()->Get(v8::String::New("f"))); |
17410 CHECK_EQ("foo.bar.baz", *v8::String::Utf8Value(f->GetInferredName())); | 17410 CHECK_EQ("foo.bar.baz", *v8::String::Utf8Value(f->GetInferredName())); |
17411 } | 17411 } |
17412 | 17412 |
17413 | 17413 |
| 17414 THREADED_TEST(FunctionGetDisplayName) { |
| 17415 LocalContext env; |
| 17416 v8::HandleScope scope(env->GetIsolate()); |
| 17417 const char* code = "var error = false;" |
| 17418 "function a() { this.x = 1; };" |
| 17419 "a.displayName = 'display_a';" |
| 17420 "var b = (function() {" |
| 17421 " var f = function() { this.x = 2; };" |
| 17422 " f.displayName = 'display_b';" |
| 17423 " return f;" |
| 17424 "})();" |
| 17425 "var c = function() {};" |
| 17426 "c.__defineGetter__('displayName', function() {" |
| 17427 " error = true;" |
| 17428 " throw new Error();" |
| 17429 "});" |
| 17430 "function d() {};" |
| 17431 "d.__defineGetter__('displayName', function() {" |
| 17432 " error = true;" |
| 17433 " return 'wrong_display_name';" |
| 17434 "});" |
| 17435 "function e() {};" |
| 17436 "e.displayName = 'wrong_display_name';" |
| 17437 "e.__defineSetter__('displayName', function() {" |
| 17438 " error = true;" |
| 17439 " throw new Error();" |
| 17440 "});" |
| 17441 "function f() {};" |
| 17442 "f.displayName = { 'foo': 6, toString: function() {" |
| 17443 " error = true;" |
| 17444 " return 'wrong_display_name';" |
| 17445 "}};" |
| 17446 "var g = function() {" |
| 17447 " arguments.callee.displayName = 'set_in_runtime';" |
| 17448 "}; g();" |
| 17449 ; |
| 17450 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); |
| 17451 v8::Script::Compile(v8::String::New(code), &origin)->Run(); |
| 17452 v8::Local<v8::Value> error = env->Global()->Get(v8::String::New("error")); |
| 17453 v8::Local<v8::Function> a = v8::Local<v8::Function>::Cast( |
| 17454 env->Global()->Get(v8::String::New("a"))); |
| 17455 v8::Local<v8::Function> b = v8::Local<v8::Function>::Cast( |
| 17456 env->Global()->Get(v8::String::New("b"))); |
| 17457 v8::Local<v8::Function> c = v8::Local<v8::Function>::Cast( |
| 17458 env->Global()->Get(v8::String::New("c"))); |
| 17459 v8::Local<v8::Function> d = v8::Local<v8::Function>::Cast( |
| 17460 env->Global()->Get(v8::String::New("d"))); |
| 17461 v8::Local<v8::Function> e = v8::Local<v8::Function>::Cast( |
| 17462 env->Global()->Get(v8::String::New("e"))); |
| 17463 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( |
| 17464 env->Global()->Get(v8::String::New("f"))); |
| 17465 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( |
| 17466 env->Global()->Get(v8::String::New("g"))); |
| 17467 CHECK_EQ(false, error->BooleanValue()); |
| 17468 CHECK_EQ("display_a", *v8::String::Utf8Value(a->GetDisplayName())); |
| 17469 CHECK_EQ("display_b", *v8::String::Utf8Value(b->GetDisplayName())); |
| 17470 CHECK_EQ(NULL, *v8::String::Utf8Value(c->GetDisplayName())); |
| 17471 CHECK_EQ(NULL, *v8::String::Utf8Value(d->GetDisplayName())); |
| 17472 CHECK_EQ(NULL, *v8::String::Utf8Value(e->GetDisplayName())); |
| 17473 CHECK_EQ(NULL, *v8::String::Utf8Value(f->GetDisplayName())); |
| 17474 CHECK_EQ("set_in_runtime", *v8::String::Utf8Value(g->GetDisplayName())); |
| 17475 } |
| 17476 |
| 17477 |
17414 THREADED_TEST(ScriptLineNumber) { | 17478 THREADED_TEST(ScriptLineNumber) { |
17415 LocalContext env; | 17479 LocalContext env; |
17416 v8::HandleScope scope(env->GetIsolate()); | 17480 v8::HandleScope scope(env->GetIsolate()); |
17417 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); | 17481 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); |
17418 v8::Handle<v8::String> script = v8::String::New( | 17482 v8::Handle<v8::String> script = v8::String::New( |
17419 "function f() {}\n\nfunction g() {}"); | 17483 "function f() {}\n\nfunction g() {}"); |
17420 v8::Script::Compile(script, &origin)->Run(); | 17484 v8::Script::Compile(script, &origin)->Run(); |
17421 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( | 17485 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( |
17422 env->Global()->Get(v8::String::New("f"))); | 17486 env->Global()->Get(v8::String::New("f"))); |
17423 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( | 17487 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( |
(...skipping 3113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20537 } | 20601 } |
20538 for (int i = 0; i < runs; i++) { | 20602 for (int i = 0; i < runs; i++) { |
20539 Local<String> expected; | 20603 Local<String> expected; |
20540 if (i != 0) { | 20604 if (i != 0) { |
20541 CHECK_EQ(v8_str("escape value"), values[i]); | 20605 CHECK_EQ(v8_str("escape value"), values[i]); |
20542 } else { | 20606 } else { |
20543 CHECK(values[i].IsEmpty()); | 20607 CHECK(values[i].IsEmpty()); |
20544 } | 20608 } |
20545 } | 20609 } |
20546 } | 20610 } |
OLD | NEW |