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 |
3 | // found in the LICENSE file. |
4 | |
5 | #include "src/accessors.h" |
6 | #include "src/arguments-inl.h" |
7 | #include "src/compiler.h" |
8 | #include "src/counters.h" |
9 | #include "src/heap/heap-inl.h" // For ToBoolean. TODO(jkummerow): Drop. |
10 | #include "src/isolate-inl.h" |
11 | #include "src/runtime/runtime-utils.h" |
12 | |
13 | namespace v8 { |
14 | namespace internal { |
15 | |
16 | // TODO(5530): Remove once uses in debug.js are gone. |
17 | RUNTIME_FUNCTION(Runtime_FunctionGetScriptSource) { |
18 | HandleScope scope(isolate); |
19 | DCHECK_EQ(1, args.length()); |
20 | CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0); |
21 | |
22 | if (function->IsJSFunction()) { |
23 | Handle<Object> script( |
24 | Handle<JSFunction>::cast(function)->shared()->script(), isolate); |
25 | if (script->IsScript()) return Handle<Script>::cast(script)->source(); |
26 | } |
27 | return ReadOnlyRoots(isolate).undefined_value(); |
28 | } |
29 | |
30 | RUNTIME_FUNCTION(Runtime_FunctionGetScriptId) { |
31 | HandleScope scope(isolate); |
32 | DCHECK_EQ(1, args.length()); |
33 | CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0); |
34 | |
35 | if (function->IsJSFunction()) { |
36 | Handle<Object> script( |
37 | Handle<JSFunction>::cast(function)->shared()->script(), isolate); |
38 | if (script->IsScript()) { |
39 | return Smi::FromInt(Handle<Script>::cast(script)->id()); |
40 | } |
41 | } |
42 | return Smi::FromInt(-1); |
43 | } |
44 | |
45 | RUNTIME_FUNCTION(Runtime_FunctionGetSourceCode) { |
46 | HandleScope scope(isolate); |
47 | DCHECK_EQ(1, args.length()); |
48 | CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0); |
49 | if (function->IsJSFunction()) { |
50 | Handle<SharedFunctionInfo> shared( |
51 | Handle<JSFunction>::cast(function)->shared(), isolate); |
52 | return *SharedFunctionInfo::GetSourceCode(shared); |
53 | } |
54 | return ReadOnlyRoots(isolate).undefined_value(); |
55 | } |
56 | |
57 | |
58 | RUNTIME_FUNCTION(Runtime_FunctionGetScriptSourcePosition) { |
59 | SealHandleScope shs(isolate); |
60 | DCHECK_EQ(1, args.length()); |
61 | |
62 | CONVERT_ARG_CHECKED(JSFunction, fun, 0); |
63 | int pos = fun->shared()->StartPosition(); |
64 | return Smi::FromInt(pos); |
65 | } |
66 | |
67 | |
68 | RUNTIME_FUNCTION(Runtime_FunctionIsAPIFunction) { |
69 | SealHandleScope shs(isolate); |
70 | DCHECK_EQ(1, args.length()); |
71 | |
72 | CONVERT_ARG_CHECKED(JSFunction, f, 0); |
73 | return isolate->heap()->ToBoolean(f->shared()->IsApiFunction()); |
74 | } |
75 | |
76 | |
77 | RUNTIME_FUNCTION(Runtime_Call) { |
78 | HandleScope scope(isolate); |
79 | DCHECK_LE(2, args.length()); |
80 | int const argc = args.length() - 2; |
81 | CONVERT_ARG_HANDLE_CHECKED(Object, target, 0); |
82 | CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1); |
83 | ScopedVector<Handle<Object>> argv(argc); |
84 | for (int i = 0; i < argc; ++i) { |
85 | argv[i] = args.at(2 + i); |
86 | } |
87 | RETURN_RESULT_OR_FAILURE( |
88 | isolate, Execution::Call(isolate, target, receiver, argc, argv.start())); |
89 | } |
90 | |
91 | |
92 | RUNTIME_FUNCTION(Runtime_IsFunction) { |
93 | SealHandleScope shs(isolate); |
94 | DCHECK_EQ(1, args.length()); |
95 | CONVERT_ARG_CHECKED(Object, object, 0); |
96 | return isolate->heap()->ToBoolean(object->IsFunction()); |
97 | } |
98 | |
99 | |
100 | } // namespace internal |
101 | } // namespace v8 |
102 | |