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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 CompileRun("function foo(a,b) { return { value: a + b + this.c }; }"); | 125 CompileRun("function foo(a,b) { return { value: a + b + this.c }; }"); |
126 CompileRun("foo.prototype.c = 23;"); | 126 CompileRun("foo.prototype.c = 23;"); |
127 | 127 |
128 T.CheckCall(T.Val(32), T.Val(4), T.Val(5)); | 128 T.CheckCall(T.Val(32), T.Val(4), T.Val(5)); |
129 T.CheckCall(T.Val("xy23"), T.Val("x"), T.Val("y")); | 129 T.CheckCall(T.Val("xy23"), T.Val("x"), T.Val("y")); |
130 T.CheckCall(T.nan(), T.undefined(), T.Val(3)); | 130 T.CheckCall(T.nan(), T.undefined(), T.Val(3)); |
131 } | 131 } |
132 | 132 |
133 | 133 |
134 // TODO(titzer): factor these out into test-runtime-calls.cc | 134 // TODO(titzer): factor these out into test-runtime-calls.cc |
135 TEST(RuntimeCallCPP1) { | |
136 FLAG_allow_natives_syntax = true; | |
137 FunctionTester T("(function(a) { return %ToBool(a); })"); | |
138 | |
139 T.CheckCall(T.true_value(), T.Val(23), T.undefined()); | |
140 T.CheckCall(T.true_value(), T.Val(4.2), T.undefined()); | |
141 T.CheckCall(T.true_value(), T.Val("str"), T.undefined()); | |
142 T.CheckCall(T.true_value(), T.true_value(), T.undefined()); | |
143 T.CheckCall(T.false_value(), T.false_value(), T.undefined()); | |
144 T.CheckCall(T.false_value(), T.undefined(), T.undefined()); | |
145 T.CheckCall(T.false_value(), T.Val(0.0), T.undefined()); | |
146 } | |
147 | |
148 | |
149 TEST(RuntimeCallCPP2) { | 135 TEST(RuntimeCallCPP2) { |
150 FLAG_allow_natives_syntax = true; | 136 FLAG_allow_natives_syntax = true; |
151 FunctionTester T("(function(a,b) { return %NumberAdd(a, b); })"); | 137 FunctionTester T("(function(a,b) { return %NumberAdd(a, b); })"); |
152 | 138 |
153 T.CheckCall(T.Val(65), T.Val(42), T.Val(23)); | 139 T.CheckCall(T.Val(65), T.Val(42), T.Val(23)); |
154 T.CheckCall(T.Val(19), T.Val(42), T.Val(-23)); | 140 T.CheckCall(T.Val(19), T.Val(42), T.Val(-23)); |
155 T.CheckCall(T.Val(6.5), T.Val(4.2), T.Val(2.3)); | 141 T.CheckCall(T.Val(6.5), T.Val(4.2), T.Val(2.3)); |
156 } | 142 } |
157 | 143 |
158 | 144 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 v8::Context::Scope scope(context); | 248 v8::Context::Scope scope(context); |
263 v8::Local<v8::Value> value = CompileRun(script); | 249 v8::Local<v8::Value> value = CompileRun(script); |
264 i::Handle<i::Object> ofun = v8::Utils::OpenHandle(*value); | 250 i::Handle<i::Object> ofun = v8::Utils::OpenHandle(*value); |
265 i::Handle<i::JSFunction> jsfun = Handle<JSFunction>::cast(ofun); | 251 i::Handle<i::JSFunction> jsfun = Handle<JSFunction>::cast(ofun); |
266 jsfun->set_code(T.function->code()); | 252 jsfun->set_code(T.function->code()); |
267 jsfun->set_shared(T.function->shared()); | 253 jsfun->set_shared(T.function->shared()); |
268 context->Global()->Set(v8_str("foo"), v8::Utils::ToLocal(jsfun)); | 254 context->Global()->Set(v8_str("foo"), v8::Utils::ToLocal(jsfun)); |
269 CompileRun("var x = 24;"); | 255 CompileRun("var x = 24;"); |
270 ExpectObject("foo()", context->Global()); | 256 ExpectObject("foo()", context->Global()); |
271 } | 257 } |
OLD | NEW |