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

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

Issue 23182003: Push SetAccessor to Template (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase, grokdump 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/objects-printer.cc ('k') | test/cctest/test-declarative-accessors.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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 LocalContext env; 538 LocalContext env;
522 v8::HandleScope scope(env->GetIsolate()); 539 v8::HandleScope scope(env->GetIsolate());
523 540
524 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 541 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
525 obj->SetNamedPropertyHandler( 542 obj->SetNamedPropertyHandler(
526 JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator); 543 JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator);
527 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 544 env->Global()->Set(v8_str("obj"), obj->NewInstance());
528 v8::Handle<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}"); 545 v8::Handle<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}");
529 CHECK(CompileRun("JSON.stringify(obj)")->Equals(expected)); 546 CHECK(CompileRun("JSON.stringify(obj)")->Equals(expected));
530 } 547 }
OLDNEW
« no previous file with comments | « src/objects-printer.cc ('k') | test/cctest/test-declarative-accessors.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698