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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 115 } |
116 | 116 |
117 int foo, bar, baz; | 117 int foo, bar, baz; |
118 | 118 |
119 THREADED_TEST(GlobalVariableAccess) { | 119 THREADED_TEST(GlobalVariableAccess) { |
120 foo = 0; | 120 foo = 0; |
121 bar = -4; | 121 bar = -4; |
122 baz = 10; | 122 baz = 10; |
123 v8::HandleScope scope(CcTest::isolate()); | 123 v8::HandleScope scope(CcTest::isolate()); |
124 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | 124 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); |
125 templ->InstanceTemplate()->SetAccessor(v8_str("foo"), | 125 templ->InstanceTemplate()->SetAccessor( |
126 GetIntValue, | 126 v8_str("foo"), GetIntValue, SetIntValue, |
127 SetIntValue, | 127 v8::External::New(CcTest::isolate(), &foo)); |
128 v8::External::New(&foo)); | 128 templ->InstanceTemplate()->SetAccessor( |
129 templ->InstanceTemplate()->SetAccessor(v8_str("bar"), | 129 v8_str("bar"), GetIntValue, SetIntValue, |
130 GetIntValue, | 130 v8::External::New(CcTest::isolate(), &bar)); |
131 SetIntValue, | 131 templ->InstanceTemplate()->SetAccessor( |
132 v8::External::New(&bar)); | 132 v8_str("baz"), GetIntValue, SetIntValue, |
133 templ->InstanceTemplate()->SetAccessor(v8_str("baz"), | 133 v8::External::New(CcTest::isolate(), &baz)); |
134 GetIntValue, | |
135 SetIntValue, | |
136 v8::External::New(&baz)); | |
137 LocalContext env(0, templ->InstanceTemplate()); | 134 LocalContext env(0, templ->InstanceTemplate()); |
138 v8_compile("foo = (++bar) + baz")->Run(); | 135 v8_compile("foo = (++bar) + baz")->Run(); |
139 CHECK_EQ(bar, -3); | 136 CHECK_EQ(bar, -3); |
140 CHECK_EQ(foo, 7); | 137 CHECK_EQ(foo, 7); |
141 } | 138 } |
142 | 139 |
143 | 140 |
144 static int x_register[2] = {0, 0}; | 141 static int x_register[2] = {0, 0}; |
145 static v8::Handle<v8::Object> x_receiver; | 142 static v8::Handle<v8::Object> x_receiver; |
146 static v8::Handle<v8::Object> x_holder; | 143 static v8::Handle<v8::Object> x_holder; |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 v8::HandleScope scope(isolate); | 559 v8::HandleScope scope(isolate); |
563 v8::Handle<v8::Function> fun = v8::Function::New(isolate, handle_property); | 560 v8::Handle<v8::Function> fun = v8::Function::New(isolate, handle_property); |
564 LocalContext switch_context; | 561 LocalContext switch_context; |
565 switch_context->Global()->Set(v8_str("fun"), fun); | 562 switch_context->Global()->Set(v8_str("fun"), fun); |
566 v8::TryCatch try_catch; | 563 v8::TryCatch try_catch; |
567 CompileRun( | 564 CompileRun( |
568 "var o = Object.create(null, { n: { get:fun } });" | 565 "var o = Object.create(null, { n: { get:fun } });" |
569 "for (var i = 0; i < 10; i++) o.n;"); | 566 "for (var i = 0; i < 10; i++) o.n;"); |
570 CHECK(!try_catch.HasCaught()); | 567 CHECK(!try_catch.HasCaught()); |
571 } | 568 } |
OLD | NEW |