Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 13379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13390 CHECK_EQ(1, force_set_set_count); | 13390 CHECK_EQ(1, force_set_set_count); |
| 13391 CHECK_EQ(5, force_set_get_count); | 13391 CHECK_EQ(5, force_set_get_count); |
| 13392 // The interceptor should also work for other properties | 13392 // The interceptor should also work for other properties |
| 13393 CHECK_EQ(3, global->Get(v8::String::NewFromUtf8(isolate, "b")) | 13393 CHECK_EQ(3, global->Get(v8::String::NewFromUtf8(isolate, "b")) |
| 13394 ->Int32Value()); | 13394 ->Int32Value()); |
| 13395 CHECK_EQ(1, force_set_set_count); | 13395 CHECK_EQ(1, force_set_set_count); |
| 13396 CHECK_EQ(6, force_set_get_count); | 13396 CHECK_EQ(6, force_set_get_count); |
| 13397 } | 13397 } |
| 13398 | 13398 |
| 13399 | 13399 |
| 13400 TEST(DefineObjectProperty) { | |
| 13401 LocalContext env; | |
| 13402 v8::Isolate* isolate = env->GetIsolate(); | |
| 13403 v8::HandleScope handle_scope(isolate); | |
| 13404 | |
| 13405 CompileRun( | |
| 13406 "var a = {};" | |
| 13407 "Object.defineProperty(a, 'foo', {value: 23});"); | |
| 13408 | |
| 13409 v8::Local<v8::Object> obj = | |
| 13410 v8::Local<v8::Object>::Cast(env->Global()->Get(v8_str("a"))); | |
| 13411 | |
| 13412 { | |
| 13413 v8::TryCatch try_catch; | |
| 13414 CHECK(obj->DefineObjectProperty(env.local(), v8_str("foo"), | |
| 13415 v8::Integer::New(isolate, 42)).IsEmpty()); | |
| 13416 CHECK(try_catch.HasCaught()); | |
| 13417 } | |
| 13418 | |
| 13419 { | |
| 13420 v8::TryCatch try_catch; | |
| 13421 obj->DefineObjectProperty(env.local(), v8_str("bar"), | |
| 13422 v8::Integer::New(isolate, 42)).ToLocalChecked(); | |
| 13423 CHECK(!try_catch.HasCaught()); | |
| 13424 v8::Local<v8::Value> val = | |
| 13425 obj->Get(env.local(), v8_str("bar")).ToLocalChecked(); | |
| 13426 CHECK(val->IsNumber()); | |
| 13427 CHECK_EQ(42.0, val->NumberValue(env.local()).FromJust()); | |
| 13428 } | |
| 13429 | |
| 13430 { | |
| 13431 v8::TryCatch try_catch; | |
| 13432 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
| |
| 13433 v8::Integer::New(isolate, 23)).ToLocalChecked(); | |
| 13434 CHECK(!try_catch.HasCaught()); | |
| 13435 v8::Local<v8::Value> val = obj->Get(env.local(), 1).ToLocalChecked(); | |
| 13436 CHECK(val->IsNumber()); | |
| 13437 CHECK_EQ(23.0, val->NumberValue(env.local()).FromJust()); | |
| 13438 } | |
| 13439 | |
| 13440 CompileRun("Object.freeze(a);"); | |
| 13441 | |
| 13442 { | |
| 13443 v8::TryCatch try_catch; | |
| 13444 CHECK(obj->DefineObjectProperty(env.local(), v8_str("baz"), | |
| 13445 v8::Integer::New(isolate, 42)).IsEmpty()); | |
| 13446 CHECK(try_catch.HasCaught()); | |
| 13447 } | |
| 13448 } | |
| 13449 | |
| 13450 | |
| 13400 static v8::Local<Context> calling_context0; | 13451 static v8::Local<Context> calling_context0; |
| 13401 static v8::Local<Context> calling_context1; | 13452 static v8::Local<Context> calling_context1; |
| 13402 static v8::Local<Context> calling_context2; | 13453 static v8::Local<Context> calling_context2; |
| 13403 | 13454 |
| 13404 | 13455 |
| 13405 // Check that the call to the callback is initiated in | 13456 // Check that the call to the callback is initiated in |
| 13406 // calling_context2, the directly calling context is calling_context1 | 13457 // calling_context2, the directly calling context is calling_context1 |
| 13407 // and the callback itself is in calling_context0. | 13458 // and the callback itself is in calling_context0. |
| 13408 static void GetCallingContextCallback( | 13459 static void GetCallingContextCallback( |
| 13409 const v8::FunctionCallbackInfo<v8::Value>& args) { | 13460 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| (...skipping 8501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 21911 | 21962 |
| 21912 { | 21963 { |
| 21913 v8::HandleScope handle_scope(isolate); | 21964 v8::HandleScope handle_scope(isolate); |
| 21914 | 21965 |
| 21915 // Should work | 21966 // Should work |
| 21916 v8::Local<v8::Object> obj = v8::Object::New(isolate); | 21967 v8::Local<v8::Object> obj = v8::Object::New(isolate); |
| 21917 | 21968 |
| 21918 USE(obj); | 21969 USE(obj); |
| 21919 } | 21970 } |
| 21920 } | 21971 } |
| OLD | NEW |