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

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: 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..1602332647b79225082dcfda26dadf30e6cb4b47 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -13397,6 +13397,60 @@ 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::MaybeLocal<v8::Value> maybe_val = obj->Get(env.local(), v8_str("bar"));
+ v8::Local<v8::Value> val = maybe_val.ToLocalChecked();
dcarney 2015/04/15 08:31:17 as a rule, always try to hide Maybes and MaybeLoca
jochen (gone - plz use gerrit) 2015/04/15 08:35:18 done
+ CHECK(val->IsNumber());
+ v8::Maybe<double> num = val->NumberValue(env.local());
+ CHECK_EQ(42.0, num.FromJust());
+ }
+
+ {
+ v8::TryCatch try_catch;
+ obj->DefineObjectProperty(env.local(), v8_str("1"),
+ v8::Integer::New(isolate, 23)).ToLocalChecked();
+ CHECK(!try_catch.HasCaught());
+ v8::MaybeLocal<v8::Value> maybe_val = obj->Get(env.local(), 1);
+ v8::Local<v8::Value> val = maybe_val.ToLocalChecked();
+ CHECK(val->IsNumber());
+ v8::Maybe<double> num = val->NumberValue(env.local());
+ CHECK_EQ(23.0, num.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