Chromium Code Reviews| 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; |