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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 using ::v8::AccessorInfo; | 44 using ::v8::AccessorInfo; |
45 using ::v8::Extension; | 45 using ::v8::Extension; |
46 | 46 |
47 static void handle_property(Local<String> name, | 47 static void handle_property(Local<String> name, |
48 const v8::PropertyCallbackInfo<v8::Value>& info) { | 48 const v8::PropertyCallbackInfo<v8::Value>& info) { |
49 ApiTestFuzzer::Fuzz(); | 49 ApiTestFuzzer::Fuzz(); |
50 info.GetReturnValue().Set(v8_num(900)); | 50 info.GetReturnValue().Set(v8_num(900)); |
51 } | 51 } |
52 | 52 |
53 | 53 |
| 54 static void handle_property(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 55 ApiTestFuzzer::Fuzz(); |
| 56 CHECK_EQ(0, info.Length()); |
| 57 info.GetReturnValue().Set(v8_num(907)); |
| 58 } |
| 59 |
| 60 |
54 THREADED_TEST(PropertyHandler) { | 61 THREADED_TEST(PropertyHandler) { |
55 LocalContext env; | 62 LocalContext env; |
56 v8::HandleScope scope(env->GetIsolate()); | 63 v8::HandleScope scope(env->GetIsolate()); |
57 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 64 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
58 fun_templ->InstanceTemplate()->SetAccessor(v8_str("foo"), handle_property); | 65 fun_templ->InstanceTemplate()->SetAccessor(v8_str("foo"), handle_property); |
| 66 Local<v8::FunctionTemplate> getter_templ = |
| 67 v8::FunctionTemplate::New(handle_property); |
| 68 getter_templ->SetLength(0); |
| 69 fun_templ-> |
| 70 InstanceTemplate()->SetAccessorProperty(v8_str("bar"), getter_templ); |
59 Local<Function> fun = fun_templ->GetFunction(); | 71 Local<Function> fun = fun_templ->GetFunction(); |
60 env->Global()->Set(v8_str("Fun"), fun); | 72 env->Global()->Set(v8_str("Fun"), fun); |
61 Local<Script> getter = v8_compile("var obj = new Fun(); obj.foo;"); | 73 Local<Script> getter = v8_compile("var obj = new Fun(); obj.foo;"); |
62 CHECK_EQ(900, getter->Run()->Int32Value()); | 74 CHECK_EQ(900, getter->Run()->Int32Value()); |
63 Local<Script> setter = v8_compile("obj.foo = 901;"); | 75 Local<Script> setter = v8_compile("obj.foo = 901;"); |
64 CHECK_EQ(901, setter->Run()->Int32Value()); | 76 CHECK_EQ(901, setter->Run()->Int32Value()); |
| 77 getter = v8_compile("obj.bar;"); |
| 78 CHECK_EQ(907, getter->Run()->Int32Value()); |
| 79 setter = v8_compile("obj.bar = 908;"); |
| 80 CHECK_EQ(908, setter->Run()->Int32Value()); |
65 } | 81 } |
66 | 82 |
67 | 83 |
68 static void GetIntValue(Local<String> property, | 84 static void GetIntValue(Local<String> property, |
69 const v8::PropertyCallbackInfo<v8::Value>& info) { | 85 const v8::PropertyCallbackInfo<v8::Value>& info) { |
70 ApiTestFuzzer::Fuzz(); | 86 ApiTestFuzzer::Fuzz(); |
71 int* value = | 87 int* value = |
72 static_cast<int*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); | 88 static_cast<int*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); |
73 info.GetReturnValue().Set(v8_num(*value)); | 89 info.GetReturnValue().Set(v8_num(*value)); |
74 } | 90 } |
(...skipping 27 matching lines...) Expand all Loading... |
102 GetIntValue, | 118 GetIntValue, |
103 SetIntValue, | 119 SetIntValue, |
104 v8::External::New(&baz)); | 120 v8::External::New(&baz)); |
105 LocalContext env(0, templ->InstanceTemplate()); | 121 LocalContext env(0, templ->InstanceTemplate()); |
106 v8_compile("foo = (++bar) + baz")->Run(); | 122 v8_compile("foo = (++bar) + baz")->Run(); |
107 CHECK_EQ(bar, -3); | 123 CHECK_EQ(bar, -3); |
108 CHECK_EQ(foo, 7); | 124 CHECK_EQ(foo, 7); |
109 } | 125 } |
110 | 126 |
111 | 127 |
112 static int x_register = 0; | 128 static int x_register[2] = {0, 0}; |
113 static v8::Handle<v8::Object> x_receiver; | 129 static v8::Handle<v8::Object> x_receiver; |
114 static v8::Handle<v8::Object> x_holder; | 130 static v8::Handle<v8::Object> x_holder; |
115 | 131 |
| 132 template<class Info> |
| 133 static void XGetter(const Info& info, int offset) { |
| 134 ApiTestFuzzer::Fuzz(); |
| 135 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 136 CHECK_EQ(isolate, info.GetIsolate()); |
| 137 CHECK_EQ(x_receiver, info.This()); |
| 138 info.GetReturnValue().Set(v8_num(x_register[offset])); |
| 139 } |
| 140 |
116 | 141 |
117 static void XGetter(Local<String> name, | 142 static void XGetter(Local<String> name, |
118 const v8::PropertyCallbackInfo<v8::Value>& info) { | 143 const v8::PropertyCallbackInfo<v8::Value>& info) { |
119 ApiTestFuzzer::Fuzz(); | 144 CHECK_EQ(x_holder, info.Holder()); |
| 145 XGetter(info, 0); |
| 146 } |
| 147 |
| 148 |
| 149 static void XGetter(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 150 XGetter(info, 1); |
| 151 } |
| 152 |
| 153 |
| 154 template<class Info> |
| 155 static void XSetter(Local<Value> value, const Info& info, int offset) { |
120 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 156 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
121 CHECK_EQ(isolate, info.GetIsolate()); | 157 CHECK_EQ(isolate, info.GetIsolate()); |
122 CHECK_EQ(x_receiver, info.This()); | 158 CHECK_EQ(x_holder, info.This()); |
123 CHECK_EQ(x_holder, info.Holder()); | 159 x_register[offset] = value->Int32Value(); |
124 info.GetReturnValue().Set(v8_num(x_register)); | |
125 } | 160 } |
126 | 161 |
127 | 162 |
128 static void XSetter(Local<String> name, | 163 static void XSetter(Local<String> name, |
129 Local<Value> value, | 164 Local<Value> value, |
130 const v8::PropertyCallbackInfo<void>& info) { | 165 const v8::PropertyCallbackInfo<void>& info) { |
131 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
132 CHECK_EQ(isolate, info.GetIsolate()); | |
133 CHECK_EQ(x_holder, info.This()); | |
134 CHECK_EQ(x_holder, info.Holder()); | 166 CHECK_EQ(x_holder, info.Holder()); |
135 x_register = value->Int32Value(); | 167 XSetter(value, info, 0); |
136 } | 168 } |
137 | 169 |
138 | 170 |
| 171 static void XSetter(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 172 CHECK_EQ(1, info.Length()); |
| 173 XSetter(info[0], info, 1); |
| 174 } |
| 175 |
| 176 |
139 THREADED_TEST(AccessorIC) { | 177 THREADED_TEST(AccessorIC) { |
140 LocalContext context; | 178 LocalContext context; |
141 v8::HandleScope scope(context->GetIsolate()); | 179 v8::HandleScope scope(context->GetIsolate()); |
142 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 180 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); |
143 obj->SetAccessor(v8_str("x"), XGetter, XSetter); | 181 obj->SetAccessor(v8_str("x0"), XGetter, XSetter); |
| 182 obj->SetAccessorProperty(v8_str("x1"), |
| 183 v8::FunctionTemplate::New(XGetter), |
| 184 v8::FunctionTemplate::New(XSetter)); |
144 x_holder = obj->NewInstance(); | 185 x_holder = obj->NewInstance(); |
145 context->Global()->Set(v8_str("holder"), x_holder); | 186 context->Global()->Set(v8_str("holder"), x_holder); |
146 x_receiver = v8::Object::New(); | 187 x_receiver = v8::Object::New(); |
147 context->Global()->Set(v8_str("obj"), x_receiver); | 188 context->Global()->Set(v8_str("obj"), x_receiver); |
148 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(CompileRun( | 189 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(CompileRun( |
149 "obj.__proto__ = holder;" | 190 "obj.__proto__ = holder;" |
150 "var result = [];" | 191 "var result = [];" |
151 "for (var i = 0; i < 10; i++) {" | 192 "for (var i = 0; i < 10; i++) {" |
152 " holder.x = i;" | 193 " holder.x0 = i;" |
153 " result.push(obj.x);" | 194 " holder.x1 = i;" |
| 195 " result.push(obj.x0);" |
| 196 " result.push(obj.x1);" |
154 "}" | 197 "}" |
155 "result")); | 198 "result")); |
156 CHECK_EQ(10, array->Length()); | 199 CHECK_EQ(20, array->Length()); |
157 for (int i = 0; i < 10; i++) { | 200 for (int i = 0; i < 20; i++) { |
158 v8::Handle<Value> entry = array->Get(v8::Integer::New(i)); | 201 v8::Handle<Value> entry = array->Get(v8::Integer::New(i)); |
159 CHECK_EQ(v8::Integer::New(i), entry); | 202 CHECK_EQ(v8::Integer::New(i/2), entry); |
160 } | 203 } |
161 } | 204 } |
162 | 205 |
163 | 206 |
164 static void AccessorProhibitsOverwritingGetter( | 207 static void AccessorProhibitsOverwritingGetter( |
165 Local<String> name, | 208 Local<String> name, |
166 const v8::PropertyCallbackInfo<v8::Value>& info) { | 209 const v8::PropertyCallbackInfo<v8::Value>& info) { |
167 ApiTestFuzzer::Fuzz(); | 210 ApiTestFuzzer::Fuzz(); |
168 info.GetReturnValue().Set(true); | 211 info.GetReturnValue().Set(true); |
169 } | 212 } |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 LocalContext env; | 521 LocalContext env; |
479 v8::HandleScope scope(env->GetIsolate()); | 522 v8::HandleScope scope(env->GetIsolate()); |
480 | 523 |
481 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 524 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); |
482 obj->SetNamedPropertyHandler( | 525 obj->SetNamedPropertyHandler( |
483 JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator); | 526 JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator); |
484 env->Global()->Set(v8_str("obj"), obj->NewInstance()); | 527 env->Global()->Set(v8_str("obj"), obj->NewInstance()); |
485 v8::Handle<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}"); | 528 v8::Handle<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}"); |
486 CHECK(CompileRun("JSON.stringify(obj)")->Equals(expected)); | 529 CHECK(CompileRun("JSON.stringify(obj)")->Equals(expected)); |
487 } | 530 } |
OLD | NEW |