| 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 // TODO(jochen): Remove this after the setting is turned on globally. |
| 6 #define V8_IMMINENT_DEPRECATION_WARNINGS |
| 7 |
| 5 #include "src/v8.h" | 8 #include "src/v8.h" |
| 6 | 9 |
| 7 #include "test/cctest/compiler/function-tester.h" | 10 #include "test/cctest/compiler/function-tester.h" |
| 8 | 11 |
| 9 using namespace v8::internal; | 12 using namespace v8::internal; |
| 10 using namespace v8::internal::compiler; | 13 using namespace v8::internal::compiler; |
| 11 | 14 |
| 12 TEST(SimpleCall) { | 15 TEST(SimpleCall) { |
| 13 FunctionTester T("(function(foo,a) { return foo(a); })"); | 16 FunctionTester T("(function(foo,a) { return foo(a); })"); |
| 14 Handle<JSFunction> foo = T.NewFunction("(function(a) { return a; })"); | 17 Handle<JSFunction> foo = T.NewFunction("(function(a) { return a; })"); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 | 211 |
| 209 // Disable context specialization. | 212 // Disable context specialization. |
| 210 FunctionTester T(script); | 213 FunctionTester T(script); |
| 211 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); | 214 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 212 v8::Context::Scope scope(context); | 215 v8::Context::Scope scope(context); |
| 213 v8::Local<v8::Value> value = CompileRun(script); | 216 v8::Local<v8::Value> value = CompileRun(script); |
| 214 i::Handle<i::Object> ofun = v8::Utils::OpenHandle(*value); | 217 i::Handle<i::Object> ofun = v8::Utils::OpenHandle(*value); |
| 215 i::Handle<i::JSFunction> jsfun = Handle<JSFunction>::cast(ofun); | 218 i::Handle<i::JSFunction> jsfun = Handle<JSFunction>::cast(ofun); |
| 216 jsfun->set_code(T.function->code()); | 219 jsfun->set_code(T.function->code()); |
| 217 jsfun->set_shared(T.function->shared()); | 220 jsfun->set_shared(T.function->shared()); |
| 218 context->Global()->Set(v8_str("foo"), v8::Utils::CallableToLocal(jsfun)); | 221 CHECK(context->Global() |
| 222 ->Set(context, v8_str("foo"), v8::Utils::CallableToLocal(jsfun)) |
| 223 .FromJust()); |
| 219 CompileRun("var x = 24;"); | 224 CompileRun("var x = 24;"); |
| 220 ExpectInt32("foo();", 24); | 225 ExpectInt32("foo();", 24); |
| 221 } | 226 } |
| 222 | 227 |
| 223 | 228 |
| 224 TEST(BuiltinLoadedFromActivation) { | 229 TEST(BuiltinLoadedFromActivation) { |
| 225 const char* script = | 230 const char* script = |
| 226 "var x = 42;" | 231 "var x = 42;" |
| 227 "(function() {" | 232 "(function() {" |
| 228 " return function () { return this; };" | 233 " return function () { return this; };" |
| 229 "})()"; | 234 "})()"; |
| 230 | 235 |
| 231 // Disable context specialization. | 236 // Disable context specialization. |
| 232 FunctionTester T(script); | 237 FunctionTester T(script); |
| 233 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); | 238 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 234 v8::Context::Scope scope(context); | 239 v8::Context::Scope scope(context); |
| 235 v8::Local<v8::Value> value = CompileRun(script); | 240 v8::Local<v8::Value> value = CompileRun(script); |
| 236 i::Handle<i::Object> ofun = v8::Utils::OpenHandle(*value); | 241 i::Handle<i::Object> ofun = v8::Utils::OpenHandle(*value); |
| 237 i::Handle<i::JSFunction> jsfun = Handle<JSFunction>::cast(ofun); | 242 i::Handle<i::JSFunction> jsfun = Handle<JSFunction>::cast(ofun); |
| 238 jsfun->set_code(T.function->code()); | 243 jsfun->set_code(T.function->code()); |
| 239 jsfun->set_shared(T.function->shared()); | 244 jsfun->set_shared(T.function->shared()); |
| 240 context->Global()->Set(v8_str("foo"), v8::Utils::CallableToLocal(jsfun)); | 245 CHECK(context->Global() |
| 246 ->Set(context, v8_str("foo"), v8::Utils::CallableToLocal(jsfun)) |
| 247 .FromJust()); |
| 241 CompileRun("var x = 24;"); | 248 CompileRun("var x = 24;"); |
| 242 ExpectObject("foo()", context->Global()); | 249 ExpectObject("foo()", context->Global()); |
| 243 } | 250 } |
| OLD | NEW |