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