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

Side by Side 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 unified diff | Download patch
« src/v8natives.js ('K') | « src/v8natives.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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::MaybeLocal<v8::Value> maybe_val = obj->Get(env.local(), v8_str("bar"));
13425 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
13426 CHECK(val->IsNumber());
13427 v8::Maybe<double> num = val->NumberValue(env.local());
13428 CHECK_EQ(42.0, num.FromJust());
13429 }
13430
13431 {
13432 v8::TryCatch try_catch;
13433 obj->DefineObjectProperty(env.local(), v8_str("1"),
13434 v8::Integer::New(isolate, 23)).ToLocalChecked();
13435 CHECK(!try_catch.HasCaught());
13436 v8::MaybeLocal<v8::Value> maybe_val = obj->Get(env.local(), 1);
13437 v8::Local<v8::Value> val = maybe_val.ToLocalChecked();
13438 CHECK(val->IsNumber());
13439 v8::Maybe<double> num = val->NumberValue(env.local());
13440 CHECK_EQ(23.0, num.FromJust());
13441 }
13442
13443 CompileRun("Object.freeze(a);");
13444
13445 {
13446 v8::TryCatch try_catch;
13447 CHECK(obj->DefineObjectProperty(env.local(), v8_str("baz"),
13448 v8::Integer::New(isolate, 42)).IsEmpty());
13449 CHECK(try_catch.HasCaught());
13450 }
13451 }
13452
13453
13400 static v8::Local<Context> calling_context0; 13454 static v8::Local<Context> calling_context0;
13401 static v8::Local<Context> calling_context1; 13455 static v8::Local<Context> calling_context1;
13402 static v8::Local<Context> calling_context2; 13456 static v8::Local<Context> calling_context2;
13403 13457
13404 13458
13405 // Check that the call to the callback is initiated in 13459 // Check that the call to the callback is initiated in
13406 // calling_context2, the directly calling context is calling_context1 13460 // calling_context2, the directly calling context is calling_context1
13407 // and the callback itself is in calling_context0. 13461 // and the callback itself is in calling_context0.
13408 static void GetCallingContextCallback( 13462 static void GetCallingContextCallback(
13409 const v8::FunctionCallbackInfo<v8::Value>& args) { 13463 const v8::FunctionCallbackInfo<v8::Value>& args) {
(...skipping 8501 matching lines...) Expand 10 before | Expand all | Expand 10 after
21911 21965
21912 { 21966 {
21913 v8::HandleScope handle_scope(isolate); 21967 v8::HandleScope handle_scope(isolate);
21914 21968
21915 // Should work 21969 // Should work
21916 v8::Local<v8::Object> obj = v8::Object::New(isolate); 21970 v8::Local<v8::Object> obj = v8::Object::New(isolate);
21917 21971
21918 USE(obj); 21972 USE(obj);
21919 } 21973 }
21920 } 21974 }
OLDNEW
« 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