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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/frames-inl.h" | 10 #include "src/frames-inl.h" |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 argv[i] = args.at<Object>(2 + i); | 260 argv[i] = args.at<Object>(2 + i); |
261 } | 261 } |
262 Handle<Object> result; | 262 Handle<Object> result; |
263 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 263 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
264 isolate, result, | 264 isolate, result, |
265 Execution::Call(isolate, target, receiver, argc, argv.start())); | 265 Execution::Call(isolate, target, receiver, argc, argv.start())); |
266 return *result; | 266 return *result; |
267 } | 267 } |
268 | 268 |
269 | 269 |
270 RUNTIME_FUNCTION(Runtime_TailCall) { | |
271 HandleScope scope(isolate); | |
272 DCHECK_LE(2, args.length()); | |
273 int const argc = args.length() - 2; | |
274 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, target, 0); | |
275 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1); | |
276 ScopedVector<Handle<Object>> argv(argc); | |
277 for (int i = 0; i < argc; ++i) { | |
278 argv[i] = args.at<Object>(2 + i); | |
279 } | |
280 Handle<Object> result; | |
281 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
282 isolate, result, | |
283 Execution::Call(isolate, target, receiver, argc, argv.start())); | |
284 return *result; | |
285 } | |
286 | |
287 | |
288 RUNTIME_FUNCTION(Runtime_Apply) { | |
289 HandleScope scope(isolate); | |
290 DCHECK(args.length() == 5); | |
291 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, fun, 0); | |
292 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1); | |
293 CONVERT_ARG_HANDLE_CHECKED(JSObject, arguments, 2); | |
294 CONVERT_INT32_ARG_CHECKED(offset, 3); | |
295 CONVERT_INT32_ARG_CHECKED(argc, 4); | |
296 RUNTIME_ASSERT(offset >= 0); | |
297 // Loose upper bound to allow fuzzing. We'll most likely run out of | |
298 // stack space before hitting this limit. | |
299 static int kMaxArgc = 1000000; | |
300 RUNTIME_ASSERT(argc >= 0 && argc <= kMaxArgc); | |
301 | |
302 // If there are too many arguments, allocate argv via malloc. | |
303 const int argv_small_size = 10; | |
304 Handle<Object> argv_small_buffer[argv_small_size]; | |
305 base::SmartArrayPointer<Handle<Object> > argv_large_buffer; | |
306 Handle<Object>* argv = argv_small_buffer; | |
307 if (argc > argv_small_size) { | |
308 argv = new Handle<Object>[argc]; | |
309 if (argv == NULL) return isolate->StackOverflow(); | |
310 argv_large_buffer = base::SmartArrayPointer<Handle<Object> >(argv); | |
311 } | |
312 | |
313 for (int i = 0; i < argc; ++i) { | |
314 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
315 isolate, argv[i], Object::GetElement(isolate, arguments, offset + i)); | |
316 } | |
317 | |
318 Handle<Object> result; | |
319 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
320 isolate, result, Execution::Call(isolate, fun, receiver, argc, argv)); | |
321 return *result; | |
322 } | |
323 | |
324 | |
325 // ES6 section 9.2.1.2, OrdinaryCallBindThis for sloppy callee. | 270 // ES6 section 9.2.1.2, OrdinaryCallBindThis for sloppy callee. |
326 RUNTIME_FUNCTION(Runtime_ConvertReceiver) { | 271 RUNTIME_FUNCTION(Runtime_ConvertReceiver) { |
327 HandleScope scope(isolate); | 272 HandleScope scope(isolate); |
328 DCHECK(args.length() == 1); | 273 DCHECK(args.length() == 1); |
329 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0); | 274 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0); |
330 if (receiver->IsNull() || receiver->IsUndefined()) { | 275 if (receiver->IsNull() || receiver->IsUndefined()) { |
331 return isolate->global_proxy(); | 276 return isolate->global_proxy(); |
332 } | 277 } |
333 return *Object::ToObject(isolate, receiver).ToHandleChecked(); | 278 return *Object::ToObject(isolate, receiver).ToHandleChecked(); |
334 } | 279 } |
(...skipping 20 matching lines...) Expand all Loading... |
355 DCHECK_EQ(1, args.length()); | 300 DCHECK_EQ(1, args.length()); |
356 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0); | 301 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0); |
357 return function->IsJSBoundFunction() | 302 return function->IsJSBoundFunction() |
358 ? *JSBoundFunction::ToString( | 303 ? *JSBoundFunction::ToString( |
359 Handle<JSBoundFunction>::cast(function)) | 304 Handle<JSBoundFunction>::cast(function)) |
360 : *JSFunction::ToString(Handle<JSFunction>::cast(function)); | 305 : *JSFunction::ToString(Handle<JSFunction>::cast(function)); |
361 } | 306 } |
362 | 307 |
363 } // namespace internal | 308 } // namespace internal |
364 } // namespace v8 | 309 } // namespace v8 |
OLD | NEW |