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

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

Issue 23984002: load ics for js api accessors (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 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/x64/stub-cache-x64.cc ('k') | test/cctest/test-api.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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 156
157 157
158 static void XGetter(Local<String> name, 158 static void XGetter(Local<String> name,
159 const v8::PropertyCallbackInfo<v8::Value>& info) { 159 const v8::PropertyCallbackInfo<v8::Value>& info) {
160 CHECK_EQ(x_holder, info.Holder()); 160 CHECK_EQ(x_holder, info.Holder());
161 XGetter(info, 0); 161 XGetter(info, 0);
162 } 162 }
163 163
164 164
165 static void XGetter(const v8::FunctionCallbackInfo<v8::Value>& info) { 165 static void XGetter(const v8::FunctionCallbackInfo<v8::Value>& info) {
166 CHECK_EQ(x_receiver, info.Holder());
166 XGetter(info, 1); 167 XGetter(info, 1);
167 } 168 }
168 169
169 170
170 template<class Info> 171 template<class Info>
171 static void XSetter(Local<Value> value, const Info& info, int offset) { 172 static void XSetter(Local<Value> value, const Info& info, int offset) {
172 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 173 v8::Isolate* isolate = v8::Isolate::GetCurrent();
173 CHECK_EQ(isolate, info.GetIsolate()); 174 CHECK_EQ(isolate, info.GetIsolate());
174 CHECK_EQ(x_holder, info.This()); 175 CHECK_EQ(x_holder, info.This());
176 CHECK_EQ(x_holder, info.Holder());
175 x_register[offset] = value->Int32Value(); 177 x_register[offset] = value->Int32Value();
176 } 178 }
177 179
178 180
179 static void XSetter(Local<String> name, 181 static void XSetter(Local<String> name,
180 Local<Value> value, 182 Local<Value> value,
181 const v8::PropertyCallbackInfo<void>& info) { 183 const v8::PropertyCallbackInfo<void>& info) {
182 CHECK_EQ(x_holder, info.Holder());
183 XSetter(value, info, 0); 184 XSetter(value, info, 0);
184 } 185 }
185 186
186 187
187 static void XSetter(const v8::FunctionCallbackInfo<v8::Value>& info) { 188 static void XSetter(const v8::FunctionCallbackInfo<v8::Value>& info) {
188 CHECK_EQ(1, info.Length()); 189 CHECK_EQ(1, info.Length());
189 XSetter(info[0], info, 1); 190 XSetter(info[0], info, 1);
190 } 191 }
191 192
192 193
193 THREADED_TEST(AccessorIC) { 194 THREADED_TEST(AccessorIC) {
194 LocalContext context; 195 LocalContext context;
195 v8::HandleScope scope(context->GetIsolate()); 196 v8::HandleScope scope(context->GetIsolate());
196 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 197 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
197 obj->SetAccessor(v8_str("x0"), XGetter, XSetter); 198 obj->SetAccessor(v8_str("x0"), XGetter, XSetter);
198 obj->SetAccessorProperty(v8_str("x1"), 199 obj->SetAccessorProperty(v8_str("x1"),
199 v8::FunctionTemplate::New(XGetter), 200 v8::FunctionTemplate::New(XGetter),
200 v8::FunctionTemplate::New(XSetter)); 201 v8::FunctionTemplate::New(XSetter));
201 x_holder = obj->NewInstance(); 202 x_holder = obj->NewInstance();
202 context->Global()->Set(v8_str("holder"), x_holder); 203 context->Global()->Set(v8_str("holder"), x_holder);
203 x_receiver = v8::Object::New(); 204 x_receiver = v8::Object::New();
204 context->Global()->Set(v8_str("obj"), x_receiver); 205 context->Global()->Set(v8_str("obj"), x_receiver);
205 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(CompileRun( 206 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(CompileRun(
206 "obj.__proto__ = holder;" 207 "obj.__proto__ = holder;"
207 "var result = [];" 208 "var result = [];"
209 "var key_0 = 'x0';"
210 "var key_1 = 'x1';"
208 "for (var i = 0; i < 10; i++) {" 211 "for (var i = 0; i < 10; i++) {"
209 " holder.x0 = i;" 212 " holder.x0 = i;"
213 " result.push(obj.x0);"
210 " holder.x1 = i;" 214 " holder.x1 = i;"
211 " result.push(obj.x0);"
212 " result.push(obj.x1);" 215 " result.push(obj.x1);"
216 " holder[key_0] = i;"
217 " result.push(obj[key_0]);"
218 " holder[key_1] = i;"
219 " result.push(obj[key_1]);"
213 "}" 220 "}"
214 "result")); 221 "result"));
215 CHECK_EQ(20, array->Length()); 222 CHECK_EQ(40, array->Length());
216 for (int i = 0; i < 20; i++) { 223 for (int i = 0; i < 40; i++) {
217 v8::Handle<Value> entry = array->Get(v8::Integer::New(i)); 224 v8::Handle<Value> entry = array->Get(v8::Integer::New(i));
218 CHECK_EQ(v8::Integer::New(i/2), entry); 225 CHECK_EQ(v8::Integer::New(i/4), entry);
219 } 226 }
220 } 227 }
221 228
222 229
223 static void AccessorProhibitsOverwritingGetter( 230 static void AccessorProhibitsOverwritingGetter(
224 Local<String> name, 231 Local<String> name,
225 const v8::PropertyCallbackInfo<v8::Value>& info) { 232 const v8::PropertyCallbackInfo<v8::Value>& info) {
226 ApiTestFuzzer::Fuzz(); 233 ApiTestFuzzer::Fuzz();
227 info.GetReturnValue().Set(true); 234 info.GetReturnValue().Set(true);
228 } 235 }
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 LocalContext env; 545 LocalContext env;
539 v8::HandleScope scope(env->GetIsolate()); 546 v8::HandleScope scope(env->GetIsolate());
540 547
541 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 548 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
542 obj->SetNamedPropertyHandler( 549 obj->SetNamedPropertyHandler(
543 JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator); 550 JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator);
544 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 551 env->Global()->Set(v8_str("obj"), obj->NewInstance());
545 v8::Handle<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}"); 552 v8::Handle<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}");
546 CHECK(CompileRun("JSON.stringify(obj)")->Equals(expected)); 553 CHECK(CompileRun("JSON.stringify(obj)")->Equals(expected));
547 } 554 }
OLDNEW
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698