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

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

Issue 185653004: Experimental parser: merge to r19637 (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 9 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 | « test/cctest/cctest.status ('k') | test/cctest/test-alloc.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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 } 167 }
168 168
169 169
170 template<class Info> 170 template<class Info>
171 static void XSetter(Local<Value> value, const Info& info, int offset) { 171 static void XSetter(Local<Value> value, const Info& info, int offset) {
172 v8::Isolate* isolate = CcTest::isolate(); 172 v8::Isolate* isolate = CcTest::isolate();
173 CHECK_EQ(isolate, info.GetIsolate()); 173 CHECK_EQ(isolate, info.GetIsolate());
174 CHECK_EQ(x_holder, info.This()); 174 CHECK_EQ(x_holder, info.This());
175 CHECK_EQ(x_holder, info.Holder()); 175 CHECK_EQ(x_holder, info.Holder());
176 x_register[offset] = value->Int32Value(); 176 x_register[offset] = value->Int32Value();
177 info.GetReturnValue().Set(v8_num(-1));
177 } 178 }
178 179
179 180
180 static void XSetter(Local<String> name, 181 static void XSetter(Local<String> name,
181 Local<Value> value, 182 Local<Value> value,
182 const v8::PropertyCallbackInfo<void>& info) { 183 const v8::PropertyCallbackInfo<void>& info) {
183 XSetter(value, info, 0); 184 XSetter(value, info, 0);
184 } 185 }
185 186
186 187
(...skipping 16 matching lines...) Expand all
203 context->Global()->Set(v8_str("holder"), x_holder); 204 context->Global()->Set(v8_str("holder"), x_holder);
204 x_receiver = v8::Object::New(isolate); 205 x_receiver = v8::Object::New(isolate);
205 context->Global()->Set(v8_str("obj"), x_receiver); 206 context->Global()->Set(v8_str("obj"), x_receiver);
206 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(CompileRun( 207 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(CompileRun(
207 "obj.__proto__ = holder;" 208 "obj.__proto__ = holder;"
208 "var result = [];" 209 "var result = [];"
209 "var key_0 = 'x0';" 210 "var key_0 = 'x0';"
210 "var key_1 = 'x1';" 211 "var key_1 = 'x1';"
211 "for (var j = 0; j < 10; j++) {" 212 "for (var j = 0; j < 10; j++) {"
212 " var i = 4*j;" 213 " var i = 4*j;"
213 " holder.x0 = i;" 214 " result.push(holder.x0 = i);"
214 " result.push(obj.x0);" 215 " result.push(obj.x0);"
215 " holder.x1 = i + 1;" 216 " result.push(holder.x1 = i + 1);"
216 " result.push(obj.x1);" 217 " result.push(obj.x1);"
217 " holder[key_0] = i + 2;" 218 " result.push(holder[key_0] = i + 2);"
218 " result.push(obj[key_0]);" 219 " result.push(obj[key_0]);"
219 " holder[key_1] = i + 3;" 220 " result.push(holder[key_1] = i + 3);"
220 " result.push(obj[key_1]);" 221 " result.push(obj[key_1]);"
221 "}" 222 "}"
222 "result")); 223 "result"));
223 CHECK_EQ(40, array->Length()); 224 CHECK_EQ(80, array->Length());
224 for (int i = 0; i < 40; i++) { 225 for (int i = 0; i < 80; i++) {
225 v8::Handle<Value> entry = array->Get(v8::Integer::New(isolate, i)); 226 v8::Handle<Value> entry = array->Get(v8::Integer::New(isolate, i));
226 CHECK_EQ(v8::Integer::New(isolate, i), entry); 227 CHECK_EQ(v8::Integer::New(isolate, i/2), entry);
227 } 228 }
228 } 229 }
229 230
230 231
231 static void AccessorProhibitsOverwritingGetter( 232 static void AccessorProhibitsOverwritingGetter(
232 Local<String> name, 233 Local<String> name,
233 const v8::PropertyCallbackInfo<v8::Value>& info) { 234 const v8::PropertyCallbackInfo<v8::Value>& info) {
234 ApiTestFuzzer::Fuzz(); 235 ApiTestFuzzer::Fuzz();
235 info.GetReturnValue().Set(true); 236 info.GetReturnValue().Set(true);
236 } 237 }
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 574
574 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); 575 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
575 obj->SetNamedPropertyHandler( 576 obj->SetNamedPropertyHandler(
576 JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator); 577 JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator);
577 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 578 env->Global()->Set(v8_str("obj"), obj->NewInstance());
578 v8::Handle<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}"); 579 v8::Handle<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}");
579 CHECK(CompileRun("JSON.stringify(obj)")->Equals(expected)); 580 CHECK(CompileRun("JSON.stringify(obj)")->Equals(expected));
580 } 581 }
581 582
582 583
584 static v8::Local<v8::Context> expected_current_context;
585 static v8::Local<v8::Context> expected_calling_context;
586
587
588 static void check_contexts(const v8::FunctionCallbackInfo<v8::Value>& info) {
589 ApiTestFuzzer::Fuzz();
590 CHECK(expected_current_context == info.GetIsolate()->GetCurrentContext());
591 CHECK(expected_calling_context == info.GetIsolate()->GetCallingContext());
592 }
593
594
583 THREADED_TEST(AccessorPropertyCrossContext) { 595 THREADED_TEST(AccessorPropertyCrossContext) {
584 LocalContext env; 596 LocalContext env;
585 v8::Isolate* isolate = env->GetIsolate(); 597 v8::Isolate* isolate = env->GetIsolate();
586 v8::HandleScope scope(isolate); 598 v8::HandleScope scope(isolate);
587 v8::Handle<v8::Function> fun = v8::Function::New(isolate, handle_property); 599 v8::Handle<v8::Function> fun = v8::Function::New(isolate, check_contexts);
588 LocalContext switch_context; 600 LocalContext switch_context;
589 switch_context->Global()->Set(v8_str("fun"), fun); 601 switch_context->Global()->Set(v8_str("fun"), fun);
590 v8::TryCatch try_catch; 602 v8::TryCatch try_catch;
603 expected_current_context = env.local();
604 expected_calling_context = switch_context.local();
591 CompileRun( 605 CompileRun(
592 "var o = Object.create(null, { n: { get:fun } });" 606 "var o = Object.create(null, { n: { get:fun } });"
593 "for (var i = 0; i < 10; i++) o.n;"); 607 "for (var i = 0; i < 10; i++) o.n;");
594 CHECK(!try_catch.HasCaught()); 608 CHECK(!try_catch.HasCaught());
595 } 609 }
610
611
612 THREADED_TEST(GlobalObjectAccessor) {
613 LocalContext env;
614 v8::Isolate* isolate = env->GetIsolate();
615 v8::HandleScope scope(isolate);
616 CompileRun(
617 "var set_value = 1;"
618 "Object.defineProperty(this.__proto__, 'x', {"
619 " get : function() { return this; },"
620 " set : function() { set_value = this; }"
621 "});"
622 "function getter() { return x; }"
623 "function setter() { x = 1; }"
624 "for (var i = 0; i < 4; i++) { getter(); setter(); }");
625 CHECK(v8::Utils::OpenHandle(*CompileRun("getter()"))->IsJSGlobalProxy());
626 CHECK(v8::Utils::OpenHandle(*CompileRun("set_value"))->IsJSGlobalProxy());
627 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.status ('k') | test/cctest/test-alloc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698