| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "test/cctest/compiler/function-tester.h" | 7 #include "test/cctest/compiler/function-tester.h" |
| 8 | 8 |
| 9 using namespace v8::internal; | 9 using namespace v8::internal; |
| 10 using namespace v8::internal::compiler; | 10 using namespace v8::internal::compiler; |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 248 |
| 249 | 249 |
| 250 TEST(ContextLoadedFromActivation) { | 250 TEST(ContextLoadedFromActivation) { |
| 251 const char* script = | 251 const char* script = |
| 252 "var x = 42;" | 252 "var x = 42;" |
| 253 "(function() {" | 253 "(function() {" |
| 254 " return function () { return x };" | 254 " return function () { return x };" |
| 255 "})()"; | 255 "})()"; |
| 256 | 256 |
| 257 // Disable context specialization. | 257 // Disable context specialization. |
| 258 FunctionTester T(script, false); | 258 FunctionTester T(script); |
| 259 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); | 259 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 260 v8::Context::Scope scope(context); | 260 v8::Context::Scope scope(context); |
| 261 v8::Local<v8::Value> value = CompileRun(script); | 261 v8::Local<v8::Value> value = CompileRun(script); |
| 262 i::Handle<i::Object> ofun = v8::Utils::OpenHandle(*value); | 262 i::Handle<i::Object> ofun = v8::Utils::OpenHandle(*value); |
| 263 i::Handle<i::JSFunction> jsfun = Handle<JSFunction>::cast(ofun); | 263 i::Handle<i::JSFunction> jsfun = Handle<JSFunction>::cast(ofun); |
| 264 jsfun->set_code(T.function->code()); | 264 jsfun->set_code(T.function->code()); |
| 265 context->Global()->Set(v8_str("foo"), v8::Utils::ToLocal(jsfun)); | 265 context->Global()->Set(v8_str("foo"), v8::Utils::ToLocal(jsfun)); |
| 266 CompileRun("var x = 24;"); | 266 CompileRun("var x = 24;"); |
| 267 ExpectInt32("foo();", 24); | 267 ExpectInt32("foo();", 24); |
| 268 } | 268 } |
| 269 | 269 |
| 270 | 270 |
| 271 TEST(BuiltinLoadedFromActivation) { | 271 TEST(BuiltinLoadedFromActivation) { |
| 272 const char* script = | 272 const char* script = |
| 273 "var x = 42;" | 273 "var x = 42;" |
| 274 "(function() {" | 274 "(function() {" |
| 275 " return function () { return this; };" | 275 " return function () { return this; };" |
| 276 "})()"; | 276 "})()"; |
| 277 | 277 |
| 278 // Disable context specialization. | 278 // Disable context specialization. |
| 279 FunctionTester T(script, false); | 279 FunctionTester T(script); |
| 280 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); | 280 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 281 v8::Context::Scope scope(context); | 281 v8::Context::Scope scope(context); |
| 282 v8::Local<v8::Value> value = CompileRun(script); | 282 v8::Local<v8::Value> value = CompileRun(script); |
| 283 i::Handle<i::Object> ofun = v8::Utils::OpenHandle(*value); | 283 i::Handle<i::Object> ofun = v8::Utils::OpenHandle(*value); |
| 284 i::Handle<i::JSFunction> jsfun = Handle<JSFunction>::cast(ofun); | 284 i::Handle<i::JSFunction> jsfun = Handle<JSFunction>::cast(ofun); |
| 285 jsfun->set_code(T.function->code()); | 285 jsfun->set_code(T.function->code()); |
| 286 context->Global()->Set(v8_str("foo"), v8::Utils::ToLocal(jsfun)); | 286 context->Global()->Set(v8_str("foo"), v8::Utils::ToLocal(jsfun)); |
| 287 CompileRun("var x = 24;"); | 287 CompileRun("var x = 24;"); |
| 288 ExpectObject("foo()", context->Global()); | 288 ExpectObject("foo()", context->Global()); |
| 289 } | 289 } |
| OLD | NEW |