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

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

Issue 1073953004: Expose Object::DefineOwnProperty on the API (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 5 years, 8 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
« src/v8natives.js ('K') | « src/v8natives.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 3f25120fac9c6f55e377f7adef6664f54174eb6c..a2bdd96cd4677ddf23d8010c0551fb1fcdd77abf 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -13397,6 +13397,57 @@ TEST(ForceSetWithInterceptor) {
}
+TEST(DefineObjectProperty) {
+ LocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope handle_scope(isolate);
+
+ CompileRun(
+ "var a = {};"
+ "Object.defineProperty(a, 'foo', {value: 23});");
+
+ v8::Local<v8::Object> obj =
+ v8::Local<v8::Object>::Cast(env->Global()->Get(v8_str("a")));
+
+ {
+ v8::TryCatch try_catch;
+ CHECK(obj->DefineObjectProperty(env.local(), v8_str("foo"),
+ v8::Integer::New(isolate, 42)).IsEmpty());
+ CHECK(try_catch.HasCaught());
+ }
+
+ {
+ v8::TryCatch try_catch;
+ obj->DefineObjectProperty(env.local(), v8_str("bar"),
+ v8::Integer::New(isolate, 42)).ToLocalChecked();
+ CHECK(!try_catch.HasCaught());
+ v8::Local<v8::Value> val =
+ obj->Get(env.local(), v8_str("bar")).ToLocalChecked();
+ CHECK(val->IsNumber());
+ CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust());
+ }
+
+ {
+ v8::TryCatch try_catch;
+ obj->DefineObjectProperty(env.local(), v8_str("1"),
adamk 2015/04/15 16:31:53 Please also add a test that passes in a v8::Intege
+ v8::Integer::New(isolate, 23)).ToLocalChecked();
+ CHECK(!try_catch.HasCaught());
+ v8::Local<v8::Value> val = obj->Get(env.local(), 1).ToLocalChecked();
+ CHECK(val->IsNumber());
+ CHECK_EQ(23.0, val->NumberValue(env.local()).FromJust());
+ }
+
+ CompileRun("Object.freeze(a);");
+
+ {
+ v8::TryCatch try_catch;
+ CHECK(obj->DefineObjectProperty(env.local(), v8_str("baz"),
+ v8::Integer::New(isolate, 42)).IsEmpty());
+ CHECK(try_catch.HasCaught());
+ }
+}
+
+
static v8::Local<Context> calling_context0;
static v8::Local<Context> calling_context1;
static v8::Local<Context> calling_context2;
« src/v8natives.js ('K') | « src/v8natives.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698