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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 using ::v8::Function; | 43 using ::v8::Function; |
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 static void handle_property_2(Local<String> name, |
| 54 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 55 ApiTestFuzzer::Fuzz(); |
| 56 info.GetReturnValue().Set(v8_num(902)); |
| 57 } |
| 58 |
53 | 59 |
54 THREADED_TEST(PropertyHandler) { | 60 THREADED_TEST(PropertyHandler) { |
55 LocalContext env; | 61 LocalContext env; |
56 v8::HandleScope scope(env->GetIsolate()); | 62 v8::HandleScope scope(env->GetIsolate()); |
57 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 63 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
58 fun_templ->InstanceTemplate()->SetAccessor(v8_str("foo"), handle_property); | 64 fun_templ->InstanceTemplate()-> |
| 65 SetNativeDataProperty(v8_str("instance_foo"), handle_property); |
| 66 fun_templ->SetNativeDataProperty(v8_str("object_foo"), handle_property_2); |
59 Local<Function> fun = fun_templ->GetFunction(); | 67 Local<Function> fun = fun_templ->GetFunction(); |
60 env->Global()->Set(v8_str("Fun"), fun); | 68 env->Global()->Set(v8_str("Fun"), fun); |
61 Local<Script> getter = v8_compile("var obj = new Fun(); obj.foo;"); | 69 Local<Script> getter; |
| 70 Local<Script> setter; |
| 71 // check function instance accessors |
| 72 getter = v8_compile("var obj = new Fun(); obj.instance_foo;"); |
62 CHECK_EQ(900, getter->Run()->Int32Value()); | 73 CHECK_EQ(900, getter->Run()->Int32Value()); |
63 Local<Script> setter = v8_compile("obj.foo = 901;"); | 74 setter = v8_compile("obj.instance_foo = 901;"); |
64 CHECK_EQ(901, setter->Run()->Int32Value()); | 75 CHECK_EQ(901, setter->Run()->Int32Value()); |
| 76 // check function static accessors |
| 77 getter = v8_compile("Fun.object_foo;"); |
| 78 CHECK_EQ(902, getter->Run()->Int32Value()); |
| 79 setter = v8_compile("Fun.object_foo = 903;"); |
| 80 CHECK_EQ(903, 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 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 LocalContext env; | 494 LocalContext env; |
479 v8::HandleScope scope(env->GetIsolate()); | 495 v8::HandleScope scope(env->GetIsolate()); |
480 | 496 |
481 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 497 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); |
482 obj->SetNamedPropertyHandler( | 498 obj->SetNamedPropertyHandler( |
483 JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator); | 499 JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator); |
484 env->Global()->Set(v8_str("obj"), obj->NewInstance()); | 500 env->Global()->Set(v8_str("obj"), obj->NewInstance()); |
485 v8::Handle<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}"); | 501 v8::Handle<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}"); |
486 CHECK(CompileRun("JSON.stringify(obj)")->Equals(expected)); | 502 CHECK(CompileRun("JSON.stringify(obj)")->Equals(expected)); |
487 } | 503 } |
OLD | NEW |