| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 using ::v8::Script; | 42 using ::v8::Script; |
| 43 using ::v8::Function; | 43 using ::v8::Function; |
| 44 using ::v8::Extension; | 44 using ::v8::Extension; |
| 45 | 45 |
| 46 static void handle_property(Local<String> name, | 46 static void handle_property(Local<String> name, |
| 47 const v8::PropertyCallbackInfo<v8::Value>& info) { | 47 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 48 ApiTestFuzzer::Fuzz(); | 48 ApiTestFuzzer::Fuzz(); |
| 49 info.GetReturnValue().Set(v8_num(900)); | 49 info.GetReturnValue().Set(v8_num(900)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 static void handle_property_2(Local<String> name, |
| 53 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 54 ApiTestFuzzer::Fuzz(); |
| 55 info.GetReturnValue().Set(v8_num(902)); |
| 56 } |
| 57 |
| 52 | 58 |
| 53 static void handle_property(const v8::FunctionCallbackInfo<v8::Value>& info) { | 59 static void handle_property(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 54 ApiTestFuzzer::Fuzz(); | 60 ApiTestFuzzer::Fuzz(); |
| 55 CHECK_EQ(0, info.Length()); | 61 CHECK_EQ(0, info.Length()); |
| 56 info.GetReturnValue().Set(v8_num(907)); | 62 info.GetReturnValue().Set(v8_num(907)); |
| 57 } | 63 } |
| 58 | 64 |
| 59 | 65 |
| 60 THREADED_TEST(PropertyHandler) { | 66 THREADED_TEST(PropertyHandler) { |
| 61 LocalContext env; | 67 LocalContext env; |
| 62 v8::HandleScope scope(env->GetIsolate()); | 68 v8::HandleScope scope(env->GetIsolate()); |
| 63 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 69 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
| 64 fun_templ->InstanceTemplate()->SetAccessor(v8_str("foo"), handle_property); | 70 fun_templ->InstanceTemplate()->SetAccessor(v8_str("foo"), handle_property); |
| 65 Local<v8::FunctionTemplate> getter_templ = | 71 Local<v8::FunctionTemplate> getter_templ = |
| 66 v8::FunctionTemplate::New(handle_property); | 72 v8::FunctionTemplate::New(handle_property); |
| 67 getter_templ->SetLength(0); | 73 getter_templ->SetLength(0); |
| 68 fun_templ-> | 74 fun_templ-> |
| 69 InstanceTemplate()->SetAccessorProperty(v8_str("bar"), getter_templ); | 75 InstanceTemplate()->SetAccessorProperty(v8_str("bar"), getter_templ); |
| 76 fun_templ->InstanceTemplate()-> |
| 77 SetNativeDataProperty(v8_str("instance_foo"), handle_property); |
| 78 fun_templ->SetNativeDataProperty(v8_str("object_foo"), handle_property_2); |
| 70 Local<Function> fun = fun_templ->GetFunction(); | 79 Local<Function> fun = fun_templ->GetFunction(); |
| 71 env->Global()->Set(v8_str("Fun"), fun); | 80 env->Global()->Set(v8_str("Fun"), fun); |
| 72 Local<Script> getter = v8_compile("var obj = new Fun(); obj.foo;"); | 81 Local<Script> getter; |
| 82 Local<Script> setter; |
| 83 // check function instance accessors |
| 84 getter = v8_compile("var obj = new Fun(); obj.instance_foo;"); |
| 73 CHECK_EQ(900, getter->Run()->Int32Value()); | 85 CHECK_EQ(900, getter->Run()->Int32Value()); |
| 74 Local<Script> setter = v8_compile("obj.foo = 901;"); | 86 setter = v8_compile("obj.instance_foo = 901;"); |
| 75 CHECK_EQ(901, setter->Run()->Int32Value()); | 87 CHECK_EQ(901, setter->Run()->Int32Value()); |
| 76 getter = v8_compile("obj.bar;"); | 88 getter = v8_compile("obj.bar;"); |
| 77 CHECK_EQ(907, getter->Run()->Int32Value()); | 89 CHECK_EQ(907, getter->Run()->Int32Value()); |
| 78 setter = v8_compile("obj.bar = 908;"); | 90 setter = v8_compile("obj.bar = 908;"); |
| 79 CHECK_EQ(908, setter->Run()->Int32Value()); | 91 CHECK_EQ(908, setter->Run()->Int32Value()); |
| 92 // check function static accessors |
| 93 getter = v8_compile("Fun.object_foo;"); |
| 94 CHECK_EQ(902, getter->Run()->Int32Value()); |
| 95 setter = v8_compile("Fun.object_foo = 903;"); |
| 96 CHECK_EQ(903, setter->Run()->Int32Value()); |
| 80 } | 97 } |
| 81 | 98 |
| 82 | 99 |
| 83 static void GetIntValue(Local<String> property, | 100 static void GetIntValue(Local<String> property, |
| 84 const v8::PropertyCallbackInfo<v8::Value>& info) { | 101 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 85 ApiTestFuzzer::Fuzz(); | 102 ApiTestFuzzer::Fuzz(); |
| 86 int* value = | 103 int* value = |
| 87 static_cast<int*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); | 104 static_cast<int*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); |
| 88 info.GetReturnValue().Set(v8_num(*value)); | 105 info.GetReturnValue().Set(v8_num(*value)); |
| 89 } | 106 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 156 |
| 140 | 157 |
| 141 static void XGetter(Local<String> name, | 158 static void XGetter(Local<String> name, |
| 142 const v8::PropertyCallbackInfo<v8::Value>& info) { | 159 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 143 CHECK_EQ(x_holder, info.Holder()); | 160 CHECK_EQ(x_holder, info.Holder()); |
| 144 XGetter(info, 0); | 161 XGetter(info, 0); |
| 145 } | 162 } |
| 146 | 163 |
| 147 | 164 |
| 148 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()); |
| 149 XGetter(info, 1); | 167 XGetter(info, 1); |
| 150 } | 168 } |
| 151 | 169 |
| 152 | 170 |
| 153 template<class Info> | 171 template<class Info> |
| 154 static void XSetter(Local<Value> value, const Info& info, int offset) { | 172 static void XSetter(Local<Value> value, const Info& info, int offset) { |
| 155 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 173 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 156 CHECK_EQ(isolate, info.GetIsolate()); | 174 CHECK_EQ(isolate, info.GetIsolate()); |
| 157 CHECK_EQ(x_holder, info.This()); | 175 CHECK_EQ(x_holder, info.This()); |
| 176 CHECK_EQ(x_holder, info.Holder()); |
| 158 x_register[offset] = value->Int32Value(); | 177 x_register[offset] = value->Int32Value(); |
| 159 } | 178 } |
| 160 | 179 |
| 161 | 180 |
| 162 static void XSetter(Local<String> name, | 181 static void XSetter(Local<String> name, |
| 163 Local<Value> value, | 182 Local<Value> value, |
| 164 const v8::PropertyCallbackInfo<void>& info) { | 183 const v8::PropertyCallbackInfo<void>& info) { |
| 165 CHECK_EQ(x_holder, info.Holder()); | |
| 166 XSetter(value, info, 0); | 184 XSetter(value, info, 0); |
| 167 } | 185 } |
| 168 | 186 |
| 169 | 187 |
| 170 static void XSetter(const v8::FunctionCallbackInfo<v8::Value>& info) { | 188 static void XSetter(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 171 CHECK_EQ(1, info.Length()); | 189 CHECK_EQ(1, info.Length()); |
| 172 XSetter(info[0], info, 1); | 190 XSetter(info[0], info, 1); |
| 173 } | 191 } |
| 174 | 192 |
| 175 | 193 |
| 176 THREADED_TEST(AccessorIC) { | 194 THREADED_TEST(AccessorIC) { |
| 177 LocalContext context; | 195 LocalContext context; |
| 178 v8::HandleScope scope(context->GetIsolate()); | 196 v8::HandleScope scope(context->GetIsolate()); |
| 179 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 197 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); |
| 180 obj->SetAccessor(v8_str("x0"), XGetter, XSetter); | 198 obj->SetAccessor(v8_str("x0"), XGetter, XSetter); |
| 181 obj->SetAccessorProperty(v8_str("x1"), | 199 obj->SetAccessorProperty(v8_str("x1"), |
| 182 v8::FunctionTemplate::New(XGetter), | 200 v8::FunctionTemplate::New(XGetter), |
| 183 v8::FunctionTemplate::New(XSetter)); | 201 v8::FunctionTemplate::New(XSetter)); |
| 184 x_holder = obj->NewInstance(); | 202 x_holder = obj->NewInstance(); |
| 185 context->Global()->Set(v8_str("holder"), x_holder); | 203 context->Global()->Set(v8_str("holder"), x_holder); |
| 186 x_receiver = v8::Object::New(); | 204 x_receiver = v8::Object::New(); |
| 187 context->Global()->Set(v8_str("obj"), x_receiver); | 205 context->Global()->Set(v8_str("obj"), x_receiver); |
| 188 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(CompileRun( | 206 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(CompileRun( |
| 189 "obj.__proto__ = holder;" | 207 "obj.__proto__ = holder;" |
| 190 "var result = [];" | 208 "var result = [];" |
| 209 "var key_0 = 'x0';" |
| 210 "var key_1 = 'x1';" |
| 191 "for (var i = 0; i < 10; i++) {" | 211 "for (var i = 0; i < 10; i++) {" |
| 192 " holder.x0 = i;" | 212 " holder.x0 = i;" |
| 213 " result.push(obj.x0);" |
| 193 " holder.x1 = i;" | 214 " holder.x1 = i;" |
| 194 " result.push(obj.x0);" | |
| 195 " 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]);" |
| 196 "}" | 220 "}" |
| 197 "result")); | 221 "result")); |
| 198 CHECK_EQ(20, array->Length()); | 222 CHECK_EQ(40, array->Length()); |
| 199 for (int i = 0; i < 20; i++) { | 223 for (int i = 0; i < 40; i++) { |
| 200 v8::Handle<Value> entry = array->Get(v8::Integer::New(i)); | 224 v8::Handle<Value> entry = array->Get(v8::Integer::New(i)); |
| 201 CHECK_EQ(v8::Integer::New(i/2), entry); | 225 CHECK_EQ(v8::Integer::New(i/4), entry); |
| 202 } | 226 } |
| 203 } | 227 } |
| 204 | 228 |
| 205 | 229 |
| 206 static void AccessorProhibitsOverwritingGetter( | 230 static void AccessorProhibitsOverwritingGetter( |
| 207 Local<String> name, | 231 Local<String> name, |
| 208 const v8::PropertyCallbackInfo<v8::Value>& info) { | 232 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 209 ApiTestFuzzer::Fuzz(); | 233 ApiTestFuzzer::Fuzz(); |
| 210 info.GetReturnValue().Set(true); | 234 info.GetReturnValue().Set(true); |
| 211 } | 235 } |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 CHECK(code->contains(pc)); | 481 CHECK(code->contains(pc)); |
| 458 iter.Advance(); | 482 iter.Advance(); |
| 459 } | 483 } |
| 460 } | 484 } |
| 461 | 485 |
| 462 | 486 |
| 463 THREADED_TEST(StackIteration) { | 487 THREADED_TEST(StackIteration) { |
| 464 LocalContext env; | 488 LocalContext env; |
| 465 v8::HandleScope scope(env->GetIsolate()); | 489 v8::HandleScope scope(env->GetIsolate()); |
| 466 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 490 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); |
| 467 i::StringStream::ClearMentionedObjectCache(); | 491 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(env->GetIsolate()); |
| 492 i::StringStream::ClearMentionedObjectCache(isolate); |
| 468 obj->SetAccessor(v8_str("xxx"), StackCheck); | 493 obj->SetAccessor(v8_str("xxx"), StackCheck); |
| 469 env->Global()->Set(v8_str("obj"), obj->NewInstance()); | 494 env->Global()->Set(v8_str("obj"), obj->NewInstance()); |
| 470 Script::Compile(String::New( | 495 Script::Compile(String::New( |
| 471 "function foo() {" | 496 "function foo() {" |
| 472 " return obj.xxx;" | 497 " return obj.xxx;" |
| 473 "}" | 498 "}" |
| 474 "for (var i = 0; i < 100; i++) {" | 499 "for (var i = 0; i < 100; i++) {" |
| 475 " foo();" | 500 " foo();" |
| 476 "}"))->Run(); | 501 "}"))->Run(); |
| 477 } | 502 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 LocalContext env; | 545 LocalContext env; |
| 521 v8::HandleScope scope(env->GetIsolate()); | 546 v8::HandleScope scope(env->GetIsolate()); |
| 522 | 547 |
| 523 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 548 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); |
| 524 obj->SetNamedPropertyHandler( | 549 obj->SetNamedPropertyHandler( |
| 525 JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator); | 550 JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator); |
| 526 env->Global()->Set(v8_str("obj"), obj->NewInstance()); | 551 env->Global()->Set(v8_str("obj"), obj->NewInstance()); |
| 527 v8::Handle<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}"); | 552 v8::Handle<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}"); |
| 528 CHECK(CompileRun("JSON.stringify(obj)")->Equals(expected)); | 553 CHECK(CompileRun("JSON.stringify(obj)")->Equals(expected)); |
| 529 } | 554 } |
| OLD | NEW |