OLD | NEW |
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 9893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9904 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); | 9904 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); |
9905 } | 9905 } |
9906 | 9906 |
9907 script = v8::Script::Compile(v8_str("new C2();")); | 9907 script = v8::Script::Compile(v8_str("new C2();")); |
9908 for (int i = 0; i < 10; i++) { | 9908 for (int i = 0; i < 10; i++) { |
9909 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); | 9909 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); |
9910 CHECK_EQ(23, c2->Get(v8_str("x"))->Int32Value()); | 9910 CHECK_EQ(23, c2->Get(v8_str("x"))->Int32Value()); |
9911 CHECK_EQ(42, c2->Get(v8_str("y"))->Int32Value()); | 9911 CHECK_EQ(42, c2->Get(v8_str("y"))->Int32Value()); |
9912 } | 9912 } |
9913 } | 9913 } |
| 9914 |
| 9915 |
| 9916 TEST(Bug618) { |
| 9917 const char* source = "function C1() {" |
| 9918 " this.x = 23;" |
| 9919 "};" |
| 9920 "C1.prototype = P;"; |
| 9921 |
| 9922 v8::HandleScope scope; |
| 9923 LocalContext context; |
| 9924 v8::Local<v8::Script> script; |
| 9925 |
| 9926 // Use a simple object as prototype. |
| 9927 v8::Local<v8::Object> prototype = v8::Object::New(); |
| 9928 prototype->Set(v8_str("y"), v8_num(42)); |
| 9929 context->Global()->Set(v8_str("P"), prototype); |
| 9930 |
| 9931 // This compile will add the code to the compilation cache. |
| 9932 CompileRun(source); |
| 9933 |
| 9934 script = v8::Script::Compile(v8_str("new C1();")); |
| 9935 for (int i = 0; i < 10; i++) { |
| 9936 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); |
| 9937 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value()); |
| 9938 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); |
| 9939 } |
| 9940 |
| 9941 // Use an API object with accessors as prototype. |
| 9942 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 9943 templ->SetAccessor(v8_str("x"), |
| 9944 GetterWhichReturns42, |
| 9945 SetterWhichSetsYOnThisTo23); |
| 9946 context->Global()->Set(v8_str("P"), templ->NewInstance()); |
| 9947 |
| 9948 // This compile will get the code from the compilation cache. |
| 9949 CompileRun(source); |
| 9950 |
| 9951 script = v8::Script::Compile(v8_str("new C1();")); |
| 9952 for (int i = 0; i < 10; i++) { |
| 9953 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); |
| 9954 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value()); |
| 9955 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value()); |
| 9956 } |
| 9957 } |
OLD | NEW |