OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/api.h" | 5 #include "src/api.h" |
6 #include "src/contexts.h" | 6 #include "src/contexts.h" |
7 #include "src/flags.h" | 7 #include "src/flags.h" |
8 #include "src/objects.h" | 8 #include "src/objects.h" |
9 #include "test/cctest/compiler/function-tester.h" | 9 #include "test/cctest/compiler/function-tester.h" |
10 | 10 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 FunctionTester T( | 198 FunctionTester T( |
199 "var x = 42;" | 199 "var x = 42;" |
200 "(function () {" | 200 "(function () {" |
201 "function bar() { return eval('x') };" | 201 "function bar() { return eval('x') };" |
202 "return bar;" | 202 "return bar;" |
203 "})();"); | 203 "})();"); |
204 | 204 |
205 T.CheckCall(T.Val(42), T.Val("x"), T.undefined()); | 205 T.CheckCall(T.Val(42), T.Val("x"), T.undefined()); |
206 } | 206 } |
207 | 207 |
208 | |
209 TEST(ContextLoadedFromActivation) { | |
210 const char* script = | |
211 "var x = 42;" | |
212 "(function() {" | |
213 " return function () { return x };" | |
214 "})()"; | |
215 | |
216 // Disable context specialization. | |
217 FunctionTester T(script); | |
218 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); | |
219 v8::Context::Scope scope(context); | |
220 v8::Local<v8::Value> value = CompileRun(script); | |
221 i::Handle<i::Object> ofun = v8::Utils::OpenHandle(*value); | |
222 i::Handle<i::JSFunction> jsfun = Handle<JSFunction>::cast(ofun); | |
223 jsfun->set_code(T.function->code()); | |
224 jsfun->set_shared(T.function->shared()); | |
225 jsfun->set_literals(T.function->literals()); | |
226 CHECK(context->Global() | |
227 ->Set(context, v8_str("foo"), v8::Utils::CallableToLocal(jsfun)) | |
228 .FromJust()); | |
229 CompileRun("var x = 24;"); | |
230 ExpectInt32("foo();", 24); | |
231 } | |
232 | |
233 | |
234 TEST(BuiltinLoadedFromActivation) { | |
235 const char* script = | |
236 "var x = 42;" | |
237 "(function() {" | |
238 " return function () { return this; };" | |
239 "})()"; | |
240 | |
241 // Disable context specialization. | |
242 FunctionTester T(script); | |
243 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); | |
244 v8::Context::Scope scope(context); | |
245 v8::Local<v8::Value> value = CompileRun(script); | |
246 i::Handle<i::Object> ofun = v8::Utils::OpenHandle(*value); | |
247 i::Handle<i::JSFunction> jsfun = Handle<JSFunction>::cast(ofun); | |
248 jsfun->set_code(T.function->code()); | |
249 jsfun->set_shared(T.function->shared()); | |
250 jsfun->set_literals(T.function->literals()); | |
251 CHECK(context->Global() | |
252 ->Set(context, v8_str("foo"), v8::Utils::CallableToLocal(jsfun)) | |
253 .FromJust()); | |
254 CompileRun("var x = 24;"); | |
255 ExpectObject("foo()", context->Global()); | |
256 } | |
257 | |
258 } // namespace compiler | 208 } // namespace compiler |
259 } // namespace internal | 209 } // namespace internal |
260 } // namespace v8 | 210 } // namespace v8 |
OLD | NEW |