Commit bc890ec2 authored by sgjesse@chromium.org's avatar sgjesse@chromium.org

Added tests for issue 618

Review URL: http://codereview.chromium.org/668055

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4025 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent afe1cfa6
......@@ -27,6 +27,8 @@
prefix cctest
test-api/Bug*: FAIL
# BUG(281): This test fails on some Linuxes.
test-debug/DebuggerAgent: PASS, (PASS || FAIL) if $system == linux
......
......@@ -9911,3 +9911,47 @@ THREADED_TEST(InterceptorOnConstructorPrototype) {
CHECK_EQ(42, c2->Get(v8_str("y"))->Int32Value());
}
}
TEST(Bug618) {
const char* source = "function C1() {"
" this.x = 23;"
"};"
"C1.prototype = P;";
v8::HandleScope scope;
LocalContext context;
v8::Local<v8::Script> script;
// Use a simple object as prototype.
v8::Local<v8::Object> prototype = v8::Object::New();
prototype->Set(v8_str("y"), v8_num(42));
context->Global()->Set(v8_str("P"), prototype);
// This compile will add the code to the compilation cache.
CompileRun(source);
script = v8::Script::Compile(v8_str("new C1();"));
for (int i = 0; i < 10; i++) {
v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run());
CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value());
CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value());
}
// Use an API object with accessors as prototype.
Local<ObjectTemplate> templ = ObjectTemplate::New();
templ->SetAccessor(v8_str("x"),
GetterWhichReturns42,
SetterWhichSetsYOnThisTo23);
context->Global()->Set(v8_str("P"), templ->NewInstance());
// This compile will get the code from the compilation cache.
CompileRun(source);
script = v8::Script::Compile(v8_str("new C1();"));
for (int i = 0; i < 10; i++) {
v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run());
CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value());
CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value());
}
}
// Copyright 2010 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// When this bug is corrected move to object-define-property and add
// additional tests for configurable in the same manner as existing tests
// there.
function C() {
this.x = 23;
}
// If a setter is added to the prototype chain of a simple constructor setting
// one of the properties assigned in the constructor then this setter is
// ignored when constructing new objects from the constructor.
// This only happens if the setter is added _after_ an instance has been
// created.
assertEquals(23, new C().x);
C.prototype.__defineSetter__('x', function(value) { this.y = 23; });
assertEquals(void 0, new C().x));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment