Index: test/cctest/test-api.cc |
=================================================================== |
--- test/cctest/test-api.cc (revision 3785) |
+++ test/cctest/test-api.cc (working copy) |
@@ -2297,7 +2297,104 @@ |
} |
} |
+THREADED_TEST(DefinePropertyOnAPIAccessor) { |
+ v8::HandleScope scope; |
+ Local<ObjectTemplate> templ = ObjectTemplate::New(); |
+ templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); |
+ LocalContext context; |
+ context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
+ // Uses getOwnPropertyDescriptor to check the configurable status |
+ Local<Script> script_desc |
+ = Script::Compile(v8_str("var prop =Object.getOwnPropertyDescriptor( " |
+ "obj, 'x');" |
+ "prop.configurable;")); |
+ Local<Value> result = script_desc->Run(); |
+ CHECK_EQ(result->BooleanValue(), true); |
+ |
+ // Redefine get - but still configurable |
+ Local<Script> script_define |
+ = Script::Compile(v8_str("var desc = { get: function(){return 42; }," |
+ " configurable: true };" |
+ "Object.defineProperty(obj, 'x', desc);" |
+ "obj.x")); |
+ result = script_define->Run(); |
+ CHECK_EQ(result, v8_num(42)); |
+ |
+ // Check that the accessor is still configurable |
+ result = script_desc->Run(); |
+ CHECK_EQ(result->BooleanValue(), true); |
+ |
+ // Redefine to a non-configurable |
+ script_define |
+ = Script::Compile(v8_str("var desc = { get: function(){return 43; }," |
+ " configurable: false };" |
+ "Object.defineProperty(obj, 'x', desc);" |
+ "obj.x")); |
+ result = script_define->Run(); |
+ CHECK_EQ(result, v8_num(43)); |
+ result = script_desc->Run(); |
+ CHECK_EQ(result->BooleanValue(), false); |
+ |
+ // Make sure that it is not possible to redefine again |
+ v8::TryCatch try_catch; |
+ result = script_define->Run(); |
+ CHECK(try_catch.HasCaught()); |
+ String::AsciiValue exception_value(try_catch.Exception()); |
+ CHECK_EQ(*exception_value, |
+ "TypeError: Cannot redefine property: defineProperty"); |
+} |
+ |
+THREADED_TEST(DefinePropertyOnDefineGetterSetter) { |
+ v8::HandleScope scope; |
+ Local<ObjectTemplate> templ = ObjectTemplate::New(); |
+ templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); |
+ LocalContext context; |
+ context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
+ |
+ Local<Script> script_desc = Script::Compile(v8_str("var prop =" |
+ "Object.getOwnPropertyDescriptor( " |
+ "obj, 'x');" |
+ "prop.configurable;")); |
+ Local<Value> result = script_desc->Run(); |
+ CHECK_EQ(result->BooleanValue(), true); |
+ |
+ Local<Script> script_define = |
+ Script::Compile(v8_str("var desc = {get: function(){return 42; }," |
+ " configurable: true };" |
+ "Object.defineProperty(obj, 'x', desc);" |
+ "obj.x")); |
+ result = script_define->Run(); |
+ CHECK_EQ(result, v8_num(42)); |
+ |
+ |
+ result = script_desc->Run(); |
+ CHECK_EQ(result->BooleanValue(), true); |
+ |
+ |
+ script_define = |
+ Script::Compile(v8_str("var desc = {get: function(){return 43; }," |
+ " configurable: false };" |
+ "Object.defineProperty(obj, 'x', desc);" |
+ "obj.x")); |
+ result = script_define->Run(); |
+ CHECK_EQ(result, v8_num(43)); |
+ result = script_desc->Run(); |
+ |
+ CHECK_EQ(result->BooleanValue(), false); |
+ |
+ v8::TryCatch try_catch; |
+ result = script_define->Run(); |
+ CHECK(try_catch.HasCaught()); |
+ String::AsciiValue exception_value(try_catch.Exception()); |
+ CHECK_EQ(*exception_value, |
+ "TypeError: Cannot redefine property: defineProperty"); |
+} |
+ |
+ |
+ |
+ |
+ |
v8::Persistent<Value> xValue; |