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

Unified Diff: test/cctest/test-api.cc

Issue 555149: Added Object.defineProperty + needed internal functionality:... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/v8natives.js ('k') | test/es5conform/es5conform.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « src/v8natives.js ('k') | test/es5conform/es5conform.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698