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

Side by Side Diff: test/cctest/test-api.cc

Issue 390833003: Remove PropertyAttributes from SetProperty (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « src/stub-cache.cc ('k') | test/cctest/test-heap.cc » ('j') | 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 4355 matching lines...) Expand 10 before | Expand all | Expand 10 after
4366 4366
4367 THREADED_TEST(PropertyAttributes) { 4367 THREADED_TEST(PropertyAttributes) {
4368 LocalContext context; 4368 LocalContext context;
4369 v8::HandleScope scope(context->GetIsolate()); 4369 v8::HandleScope scope(context->GetIsolate());
4370 // none 4370 // none
4371 Local<String> prop = v8_str("none"); 4371 Local<String> prop = v8_str("none");
4372 context->Global()->Set(prop, v8_num(7)); 4372 context->Global()->Set(prop, v8_num(7));
4373 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(prop)); 4373 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(prop));
4374 // read-only 4374 // read-only
4375 prop = v8_str("read_only"); 4375 prop = v8_str("read_only");
4376 context->Global()->Set(prop, v8_num(7), v8::ReadOnly); 4376 context->Global()->ForceSet(prop, v8_num(7), v8::ReadOnly);
4377 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value()); 4377 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value());
4378 CHECK_EQ(v8::ReadOnly, context->Global()->GetPropertyAttributes(prop)); 4378 CHECK_EQ(v8::ReadOnly, context->Global()->GetPropertyAttributes(prop));
4379 CompileRun("read_only = 9"); 4379 CompileRun("read_only = 9");
4380 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value()); 4380 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value());
4381 context->Global()->Set(prop, v8_num(10)); 4381 context->Global()->Set(prop, v8_num(10));
4382 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value()); 4382 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value());
4383 // dont-delete 4383 // dont-delete
4384 prop = v8_str("dont_delete"); 4384 prop = v8_str("dont_delete");
4385 context->Global()->Set(prop, v8_num(13), v8::DontDelete); 4385 context->Global()->ForceSet(prop, v8_num(13), v8::DontDelete);
4386 CHECK_EQ(13, context->Global()->Get(prop)->Int32Value()); 4386 CHECK_EQ(13, context->Global()->Get(prop)->Int32Value());
4387 CompileRun("delete dont_delete"); 4387 CompileRun("delete dont_delete");
4388 CHECK_EQ(13, context->Global()->Get(prop)->Int32Value()); 4388 CHECK_EQ(13, context->Global()->Get(prop)->Int32Value());
4389 CHECK_EQ(v8::DontDelete, context->Global()->GetPropertyAttributes(prop)); 4389 CHECK_EQ(v8::DontDelete, context->Global()->GetPropertyAttributes(prop));
4390 // dont-enum 4390 // dont-enum
4391 prop = v8_str("dont_enum"); 4391 prop = v8_str("dont_enum");
4392 context->Global()->Set(prop, v8_num(28), v8::DontEnum); 4392 context->Global()->ForceSet(prop, v8_num(28), v8::DontEnum);
4393 CHECK_EQ(v8::DontEnum, context->Global()->GetPropertyAttributes(prop)); 4393 CHECK_EQ(v8::DontEnum, context->Global()->GetPropertyAttributes(prop));
4394 // absent 4394 // absent
4395 prop = v8_str("absent"); 4395 prop = v8_str("absent");
4396 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(prop)); 4396 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(prop));
4397 Local<Value> fake_prop = v8_num(1); 4397 Local<Value> fake_prop = v8_num(1);
4398 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(fake_prop)); 4398 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(fake_prop));
4399 // exception 4399 // exception
4400 TryCatch try_catch; 4400 TryCatch try_catch;
4401 Local<Value> exception = 4401 Local<Value> exception =
4402 CompileRun("({ toString: function() { throw 'exception';} })"); 4402 CompileRun("({ toString: function() { throw 'exception';} })");
(...skipping 10737 matching lines...) Expand 10 before | Expand all | Expand 10 after
15140 // Test that we cannot set a property on the global object if there 15140 // Test that we cannot set a property on the global object if there
15141 // is a read-only property in the prototype chain. 15141 // is a read-only property in the prototype chain.
15142 TEST(ReadOnlyPropertyInGlobalProto) { 15142 TEST(ReadOnlyPropertyInGlobalProto) {
15143 v8::Isolate* isolate = CcTest::isolate(); 15143 v8::Isolate* isolate = CcTest::isolate();
15144 v8::HandleScope scope(isolate); 15144 v8::HandleScope scope(isolate);
15145 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); 15145 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate);
15146 LocalContext context(0, templ); 15146 LocalContext context(0, templ);
15147 v8::Handle<v8::Object> global = context->Global(); 15147 v8::Handle<v8::Object> global = context->Global();
15148 v8::Handle<v8::Object> global_proto = 15148 v8::Handle<v8::Object> global_proto =
15149 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__"))); 15149 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__")));
15150 global_proto->Set(v8_str("x"), v8::Integer::New(isolate, 0), v8::ReadOnly); 15150 global_proto->ForceSet(v8_str("x"), v8::Integer::New(isolate, 0),
15151 global_proto->Set(v8_str("y"), v8::Integer::New(isolate, 0), v8::ReadOnly); 15151 v8::ReadOnly);
15152 global_proto->ForceSet(v8_str("y"), v8::Integer::New(isolate, 0),
15153 v8::ReadOnly);
15152 // Check without 'eval' or 'with'. 15154 // Check without 'eval' or 'with'.
15153 v8::Handle<v8::Value> res = 15155 v8::Handle<v8::Value> res =
15154 CompileRun("function f() { x = 42; return x; }; f()"); 15156 CompileRun("function f() { x = 42; return x; }; f()");
15155 CHECK_EQ(v8::Integer::New(isolate, 0), res); 15157 CHECK_EQ(v8::Integer::New(isolate, 0), res);
15156 // Check with 'eval'. 15158 // Check with 'eval'.
15157 res = CompileRun("function f() { eval('1'); y = 43; return y; }; f()"); 15159 res = CompileRun("function f() { eval('1'); y = 43; return y; }; f()");
15158 CHECK_EQ(v8::Integer::New(isolate, 0), res); 15160 CHECK_EQ(v8::Integer::New(isolate, 0), res);
15159 // Check with 'with'. 15161 // Check with 'with'.
15160 res = CompileRun("function f() { with (this) { y = 44 }; return y; }; f()"); 15162 res = CompileRun("function f() { with (this) { y = 44 }; return y; }; f()");
15161 CHECK_EQ(v8::Integer::New(isolate, 0), res); 15163 CHECK_EQ(v8::Integer::New(isolate, 0), res);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
15199 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); 15201 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate);
15200 v8::Handle<v8::String> access_property = 15202 v8::Handle<v8::String> access_property =
15201 v8::String::NewFromUtf8(isolate, "a"); 15203 v8::String::NewFromUtf8(isolate, "a");
15202 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter); 15204 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter);
15203 LocalContext context(NULL, templ); 15205 LocalContext context(NULL, templ);
15204 v8::Handle<v8::Object> global = context->Global(); 15206 v8::Handle<v8::Object> global = context->Global();
15205 15207
15206 // Ordinary properties 15208 // Ordinary properties
15207 v8::Handle<v8::String> simple_property = 15209 v8::Handle<v8::String> simple_property =
15208 v8::String::NewFromUtf8(isolate, "p"); 15210 v8::String::NewFromUtf8(isolate, "p");
15209 global->Set(simple_property, v8::Int32::New(isolate, 4), v8::ReadOnly); 15211 global->ForceSet(simple_property, v8::Int32::New(isolate, 4), v8::ReadOnly);
15210 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 15212 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
15211 // This should fail because the property is read-only 15213 // This should fail because the property is read-only
15212 global->Set(simple_property, v8::Int32::New(isolate, 5)); 15214 global->Set(simple_property, v8::Int32::New(isolate, 5));
15213 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 15215 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
15214 // This should succeed even though the property is read-only 15216 // This should succeed even though the property is read-only
15215 global->ForceSet(simple_property, v8::Int32::New(isolate, 6)); 15217 global->ForceSet(simple_property, v8::Int32::New(isolate, 6));
15216 CHECK_EQ(6, global->Get(simple_property)->Int32Value()); 15218 CHECK_EQ(6, global->Get(simple_property)->Int32Value());
15217 15219
15218 // Accessors 15220 // Accessors
15219 CHECK_EQ(0, force_set_set_count); 15221 CHECK_EQ(0, force_set_set_count);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
15287 THREADED_TEST(ForceDelete) { 15289 THREADED_TEST(ForceDelete) {
15288 v8::Isolate* isolate = CcTest::isolate(); 15290 v8::Isolate* isolate = CcTest::isolate();
15289 v8::HandleScope scope(isolate); 15291 v8::HandleScope scope(isolate);
15290 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); 15292 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate);
15291 LocalContext context(NULL, templ); 15293 LocalContext context(NULL, templ);
15292 v8::Handle<v8::Object> global = context->Global(); 15294 v8::Handle<v8::Object> global = context->Global();
15293 15295
15294 // Ordinary properties 15296 // Ordinary properties
15295 v8::Handle<v8::String> simple_property = 15297 v8::Handle<v8::String> simple_property =
15296 v8::String::NewFromUtf8(isolate, "p"); 15298 v8::String::NewFromUtf8(isolate, "p");
15297 global->Set(simple_property, v8::Int32::New(isolate, 4), v8::DontDelete); 15299 global->ForceSet(simple_property, v8::Int32::New(isolate, 4), v8::DontDelete);
15298 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 15300 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
15299 // This should fail because the property is dont-delete. 15301 // This should fail because the property is dont-delete.
15300 CHECK(!global->Delete(simple_property)); 15302 CHECK(!global->Delete(simple_property));
15301 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 15303 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
15302 // This should succeed even though the property is dont-delete. 15304 // This should succeed even though the property is dont-delete.
15303 CHECK(global->ForceDelete(simple_property)); 15305 CHECK(global->ForceDelete(simple_property));
15304 CHECK(global->Get(simple_property)->IsUndefined()); 15306 CHECK(global->Get(simple_property)->IsUndefined());
15305 } 15307 }
15306 15308
15307 15309
(...skipping 16 matching lines...) Expand all
15324 15326
15325 v8::Isolate* isolate = CcTest::isolate(); 15327 v8::Isolate* isolate = CcTest::isolate();
15326 v8::HandleScope scope(isolate); 15328 v8::HandleScope scope(isolate);
15327 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); 15329 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate);
15328 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter); 15330 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter);
15329 LocalContext context(NULL, templ); 15331 LocalContext context(NULL, templ);
15330 v8::Handle<v8::Object> global = context->Global(); 15332 v8::Handle<v8::Object> global = context->Global();
15331 15333
15332 v8::Handle<v8::String> some_property = 15334 v8::Handle<v8::String> some_property =
15333 v8::String::NewFromUtf8(isolate, "a"); 15335 v8::String::NewFromUtf8(isolate, "a");
15334 global->Set(some_property, v8::Integer::New(isolate, 42), v8::DontDelete); 15336 global->ForceSet(some_property, v8::Integer::New(isolate, 42),
15337 v8::DontDelete);
15335 15338
15336 // Deleting a property should get intercepted and nothing should 15339 // Deleting a property should get intercepted and nothing should
15337 // happen. 15340 // happen.
15338 CHECK_EQ(0, force_delete_interceptor_count); 15341 CHECK_EQ(0, force_delete_interceptor_count);
15339 CHECK(global->Delete(some_property)); 15342 CHECK(global->Delete(some_property));
15340 CHECK_EQ(1, force_delete_interceptor_count); 15343 CHECK_EQ(1, force_delete_interceptor_count);
15341 CHECK_EQ(42, global->Get(some_property)->Int32Value()); 15344 CHECK_EQ(42, global->Get(some_property)->Int32Value());
15342 // Deleting the property when the interceptor returns an empty 15345 // Deleting the property when the interceptor returns an empty
15343 // handle should not delete the property since it is DontDelete. 15346 // handle should not delete the property since it is DontDelete.
15344 pass_on_delete = true; 15347 pass_on_delete = true;
(...skipping 4232 matching lines...) Expand 10 before | Expand all | Expand 10 after
19577 19580
19578 19581
19579 TEST(DontDeleteCellLoadICAPI) { 19582 TEST(DontDeleteCellLoadICAPI) {
19580 const char* function_code = 19583 const char* function_code =
19581 "function readCell() { while (true) { return cell; } }"; 19584 "function readCell() { while (true) { return cell; } }";
19582 19585
19583 // Run the code twice to initialize the load IC for a don't delete 19586 // Run the code twice to initialize the load IC for a don't delete
19584 // cell created using the API. 19587 // cell created using the API.
19585 LocalContext context; 19588 LocalContext context;
19586 v8::HandleScope scope(context->GetIsolate()); 19589 v8::HandleScope scope(context->GetIsolate());
19587 context->Global()->Set(v8_str("cell"), v8_str("value"), v8::DontDelete); 19590 context->Global()->ForceSet(v8_str("cell"), v8_str("value"), v8::DontDelete);
19588 ExpectBoolean("delete cell", false); 19591 ExpectBoolean("delete cell", false);
19589 CompileRun(function_code); 19592 CompileRun(function_code);
19590 ExpectString("readCell()", "value"); 19593 ExpectString("readCell()", "value");
19591 ExpectString("readCell()", "value"); 19594 ExpectString("readCell()", "value");
19592 19595
19593 // Delete the cell using the API and check the inlined code works 19596 // Delete the cell using the API and check the inlined code works
19594 // correctly. 19597 // correctly.
19595 CHECK(context->Global()->ForceDelete(v8_str("cell"))); 19598 CHECK(context->Global()->ForceDelete(v8_str("cell")));
19596 ExpectString("(function() {" 19599 ExpectString("(function() {"
19597 " try {" 19600 " try {"
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
20174 20177
20175 // Regression test for issue 1470. 20178 // Regression test for issue 1470.
20176 THREADED_TEST(ReadOnlyIndexedProperties) { 20179 THREADED_TEST(ReadOnlyIndexedProperties) {
20177 v8::Isolate* isolate = CcTest::isolate(); 20180 v8::Isolate* isolate = CcTest::isolate();
20178 v8::HandleScope scope(isolate); 20181 v8::HandleScope scope(isolate);
20179 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 20182 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
20180 20183
20181 LocalContext context; 20184 LocalContext context;
20182 Local<v8::Object> obj = templ->NewInstance(); 20185 Local<v8::Object> obj = templ->NewInstance();
20183 context->Global()->Set(v8_str("obj"), obj); 20186 context->Global()->Set(v8_str("obj"), obj);
20184 obj->Set(v8_str("1"), v8_str("DONT_CHANGE"), v8::ReadOnly); 20187 obj->ForceSet(v8_str("1"), v8_str("DONT_CHANGE"), v8::ReadOnly);
20185 obj->Set(v8_str("1"), v8_str("foobar")); 20188 obj->Set(v8_str("1"), v8_str("foobar"));
20186 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("1"))); 20189 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("1")));
20187 obj->Set(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly); 20190 obj->ForceSet(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly);
20188 obj->Set(v8_num(2), v8_str("foobar")); 20191 obj->Set(v8_num(2), v8_str("foobar"));
20189 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_num(2))); 20192 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_num(2)));
20190 20193
20191 // Test non-smi case. 20194 // Test non-smi case.
20192 obj->Set(v8_str("2000000000"), v8_str("DONT_CHANGE"), v8::ReadOnly); 20195 obj->ForceSet(v8_str("2000000000"), v8_str("DONT_CHANGE"), v8::ReadOnly);
20193 obj->Set(v8_str("2000000000"), v8_str("foobar")); 20196 obj->Set(v8_str("2000000000"), v8_str("foobar"));
20194 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("2000000000"))); 20197 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("2000000000")));
20195 } 20198 }
20196 20199
20197 20200
20198 THREADED_TEST(Regress1516) { 20201 THREADED_TEST(Regress1516) {
20199 LocalContext context; 20202 LocalContext context;
20200 v8::HandleScope scope(context->GetIsolate()); 20203 v8::HandleScope scope(context->GetIsolate());
20201 20204
20202 { v8::HandleScope temp_scope(context->GetIsolate()); 20205 { v8::HandleScope temp_scope(context->GetIsolate());
(...skipping 2575 matching lines...) Expand 10 before | Expand all | Expand 10 after
22778 desc = x->GetOwnPropertyDescriptor(v8_str("p1")); 22781 desc = x->GetOwnPropertyDescriptor(v8_str("p1"));
22779 Local<Function> set = 22782 Local<Function> set =
22780 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("set"))); 22783 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("set")));
22781 Local<Function> get = 22784 Local<Function> get =
22782 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("get"))); 22785 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("get")));
22783 CHECK_EQ(v8_num(13), get->Call(x, 0, NULL)); 22786 CHECK_EQ(v8_num(13), get->Call(x, 0, NULL));
22784 Handle<Value> args[] = { v8_num(14) }; 22787 Handle<Value> args[] = { v8_num(14) };
22785 set->Call(x, 1, args); 22788 set->Call(x, 1, args);
22786 CHECK_EQ(v8_num(14), get->Call(x, 0, NULL)); 22789 CHECK_EQ(v8_num(14), get->Call(x, 0, NULL));
22787 } 22790 }
OLDNEW
« no previous file with comments | « src/stub-cache.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698