Line data Source code
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 1010 : RUNTIME_FUNCTION(Runtime_FunctionGetScriptSource) {
18 : HandleScope scope(isolate);
19 : DCHECK_EQ(1, args.length());
20 505 : CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0);
21 :
22 505 : if (function->IsJSFunction()) {
23 : Handle<Object> script(
24 1010 : Handle<JSFunction>::cast(function)->shared()->script(), isolate);
25 505 : if (script->IsScript()) return Handle<Script>::cast(script)->source();
26 : }
27 : return ReadOnlyRoots(isolate).undefined_value();
28 : }
29 :
30 7610 : RUNTIME_FUNCTION(Runtime_FunctionGetScriptId) {
31 : HandleScope scope(isolate);
32 : DCHECK_EQ(1, args.length());
33 3805 : CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0);
34 :
35 3805 : if (function->IsJSFunction()) {
36 : Handle<Object> script(
37 7610 : Handle<JSFunction>::cast(function)->shared()->script(), isolate);
38 3805 : if (script->IsScript()) {
39 : return Smi::FromInt(Handle<Script>::cast(script)->id());
40 : }
41 : }
42 : return Smi::FromInt(-1);
43 : }
44 :
45 1134 : RUNTIME_FUNCTION(Runtime_FunctionGetSourceCode) {
46 : HandleScope scope(isolate);
47 : DCHECK_EQ(1, args.length());
48 567 : CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0);
49 567 : if (function->IsJSFunction()) {
50 : Handle<SharedFunctionInfo> shared(
51 : Handle<JSFunction>::cast(function)->shared(), isolate);
52 1134 : return *SharedFunctionInfo::GetSourceCode(shared);
53 : }
54 : return ReadOnlyRoots(isolate).undefined_value();
55 : }
56 :
57 :
58 3706 : RUNTIME_FUNCTION(Runtime_FunctionGetScriptSourcePosition) {
59 : SealHandleScope shs(isolate);
60 : DCHECK_EQ(1, args.length());
61 :
62 3706 : CONVERT_ARG_CHECKED(JSFunction, fun, 0);
63 1853 : int pos = fun->shared()->StartPosition();
64 : return Smi::FromInt(pos);
65 : }
66 :
67 :
68 2572 : RUNTIME_FUNCTION(Runtime_FunctionIsAPIFunction) {
69 : SealHandleScope shs(isolate);
70 : DCHECK_EQ(1, args.length());
71 :
72 2572 : CONVERT_ARG_CHECKED(JSFunction, f, 0);
73 2572 : return isolate->heap()->ToBoolean(f->shared()->IsApiFunction());
74 : }
75 :
76 :
77 1026 : RUNTIME_FUNCTION(Runtime_Call) {
78 : HandleScope scope(isolate);
79 : DCHECK_LE(2, args.length());
80 513 : int const argc = args.length() - 2;
81 : CONVERT_ARG_HANDLE_CHECKED(Object, target, 0);
82 : CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1);
83 513 : ScopedVector<Handle<Object>> argv(argc);
84 1917 : for (int i = 0; i < argc; ++i) {
85 1404 : argv[i] = args.at(2 + i);
86 : }
87 1026 : RETURN_RESULT_OR_FAILURE(
88 : isolate, Execution::Call(isolate, target, receiver, argc, argv.start()));
89 : }
90 :
91 :
92 3706 : 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 122004 : } // namespace v8
|