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

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

Issue 619006: Refactor the check for generating inline constructors... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. 1 // Copyright 2007-2009 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 9581 matching lines...) Expand 10 before | Expand all | Expand 10 after
9592 v8::Handle<v8::String> script = v8::String::New( 9592 v8::Handle<v8::String> script = v8::String::New(
9593 "function f() {}\n\nfunction g() {}"); 9593 "function f() {}\n\nfunction g() {}");
9594 v8::Script::Compile(script, &origin)->Run(); 9594 v8::Script::Compile(script, &origin)->Run();
9595 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 9595 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
9596 env->Global()->Get(v8::String::New("f"))); 9596 env->Global()->Get(v8::String::New("f")));
9597 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( 9597 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast(
9598 env->Global()->Get(v8::String::New("g"))); 9598 env->Global()->Get(v8::String::New("g")));
9599 CHECK_EQ(0, f->GetScriptLineNumber()); 9599 CHECK_EQ(0, f->GetScriptLineNumber());
9600 CHECK_EQ(2, g->GetScriptLineNumber()); 9600 CHECK_EQ(2, g->GetScriptLineNumber());
9601 } 9601 }
9602
9603
9604 static v8::Handle<Value> GetterWhichReturns42(Local<String> name,
9605 const AccessorInfo& info) {
9606 return v8_num(42);
9607 }
9608
9609
9610 static void SetterWhichSetsYOnThisTo23(Local<String> name,
9611 Local<Value> value,
9612 const AccessorInfo& info) {
9613 info.This()->Set(v8_str("y"), v8_num(23));
9614 }
9615
9616
9617 THREADED_TEST(SetterOnConstructorPrototype) {
9618 v8::HandleScope scope;
9619 Local<ObjectTemplate> templ = ObjectTemplate::New();
9620 templ->SetAccessor(v8_str("x"),
9621 GetterWhichReturns42,
9622 SetterWhichSetsYOnThisTo23);
9623 LocalContext context;
9624 context->Global()->Set(v8_str("P"), templ->NewInstance());
9625 CompileRun("function C1() {"
9626 " this.x = 23;"
9627 "};"
9628 "C1.prototype = P;"
9629 "function C2() {"
9630 " this.x = 23"
9631 "};"
9632 "C2.prototype = { };"
9633 "C2.prototype.__proto__ = P;"
9634 ""
Mads Ager (chromium) 2010/02/18 09:19:35 Remove trailing empty strings?
Søren Thygesen Gjesse 2010/02/18 09:42:52 http://codereview.chromium.org/647007
9635 ""
9636 "");
9637
9638 v8::Local<v8::Script> script;
9639 script = v8::Script::Compile(v8_str("new C1();"));
9640 for (int i = 0; i < 10; i++) {
9641 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run());
9642 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value());
9643 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value());
9644 }
9645
9646 script = v8::Script::Compile(v8_str("new C2();"));
9647 for (int i = 0; i < 10; i++) {
9648 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run());
9649 CHECK_EQ(42, c2->Get(v8_str("x"))->Int32Value());
9650 CHECK_EQ(23, c2->Get(v8_str("y"))->Int32Value());
9651 }
9652 }
9653
9654
9655 static v8::Handle<Value> NamedPropertyGetterWhichReturns42(
9656 Local<String> name, const AccessorInfo& info) {
9657 return v8_num(42);
9658 }
9659
9660
9661 static v8::Handle<Value> NamedPropertySetterWhichSetsYOnThisTo23(
9662 Local<String> name, Local<Value> value, const AccessorInfo& info) {
9663 if (name->Equals(v8_str("x"))) {
9664 info.This()->Set(v8_str("y"), v8_num(23));
9665 }
9666 return v8::Handle<Value>();
9667 }
9668
9669
9670 THREADED_TEST(InterceptorOnConstructorPrototype) {
9671 v8::HandleScope scope;
9672 Local<ObjectTemplate> templ = ObjectTemplate::New();
9673 templ->SetNamedPropertyHandler(NamedPropertyGetterWhichReturns42,
9674 NamedPropertySetterWhichSetsYOnThisTo23);
9675 LocalContext context;
9676 context->Global()->Set(v8_str("P"), templ->NewInstance());
9677 CompileRun("function C1() {"
9678 " this.x = 23;"
9679 "};"
9680 "C1.prototype = P;"
9681 "function C2() {"
9682 " this.x = 23"
9683 "};"
9684 "C2.prototype = { };"
9685 "C2.prototype.__proto__ = P;"
9686 ""
Mads Ager (chromium) 2010/02/18 09:19:35 Remove trailing empty strings?
Søren Thygesen Gjesse 2010/02/18 09:42:52 http://codereview.chromium.org/647007
9687 ""
9688 "");
9689
9690 v8::Local<v8::Script> script;
9691 script = v8::Script::Compile(v8_str("new C1();"));
9692 for (int i = 0; i < 10; i++) {
9693 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run());
9694 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value());
9695 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value());
9696 }
9697
9698 script = v8::Script::Compile(v8_str("new C2();"));
9699 for (int i = 0; i < 10; i++) {
9700 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run());
9701 CHECK_EQ(23, c2->Get(v8_str("x"))->Int32Value());
9702 CHECK_EQ(42, c2->Get(v8_str("y"))->Int32Value());
9703 }
9704 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698