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/isolate-inl.h"
10 : #include "src/runtime/runtime-utils.h"
11 :
12 : namespace v8 {
13 : namespace internal {
14 :
15 : // TODO(5530): Remove once uses in debug.js are gone.
16 505 : RUNTIME_FUNCTION(Runtime_FunctionGetScriptSource) {
17 505 : HandleScope scope(isolate);
18 : DCHECK_EQ(1, args.length());
19 1010 : CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0);
20 :
21 1010 : if (function->IsJSFunction()) {
22 : Handle<Object> script(
23 1515 : Handle<JSFunction>::cast(function)->shared()->script(), isolate);
24 1515 : if (script->IsScript()) return Handle<Script>::cast(script)->source();
25 : }
26 505 : return ReadOnlyRoots(isolate).undefined_value();
27 : }
28 :
29 3771 : RUNTIME_FUNCTION(Runtime_FunctionGetScriptId) {
30 3771 : HandleScope scope(isolate);
31 : DCHECK_EQ(1, args.length());
32 7542 : CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0);
33 :
34 7542 : if (function->IsJSFunction()) {
35 : Handle<Object> script(
36 11313 : Handle<JSFunction>::cast(function)->shared()->script(), isolate);
37 7542 : if (script->IsScript()) {
38 7542 : return Smi::FromInt(Handle<Script>::cast(script)->id());
39 : }
40 : }
41 0 : return Smi::FromInt(-1);
42 : }
43 :
44 567 : RUNTIME_FUNCTION(Runtime_FunctionGetSourceCode) {
45 567 : HandleScope scope(isolate);
46 : DCHECK_EQ(1, args.length());
47 1134 : CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0);
48 1134 : if (function->IsJSFunction()) {
49 : Handle<SharedFunctionInfo> shared(
50 1701 : Handle<JSFunction>::cast(function)->shared(), isolate);
51 1134 : return *SharedFunctionInfo::GetSourceCode(shared);
52 : }
53 567 : return ReadOnlyRoots(isolate).undefined_value();
54 : }
55 :
56 :
57 1846 : RUNTIME_FUNCTION(Runtime_FunctionGetScriptSourcePosition) {
58 : SealHandleScope shs(isolate);
59 : DCHECK_EQ(1, args.length());
60 :
61 5538 : CONVERT_ARG_CHECKED(JSFunction, fun, 0);
62 1846 : int pos = fun->shared()->StartPosition();
63 1846 : return Smi::FromInt(pos);
64 : }
65 :
66 :
67 1279 : RUNTIME_FUNCTION(Runtime_FunctionIsAPIFunction) {
68 : SealHandleScope shs(isolate);
69 : DCHECK_EQ(1, args.length());
70 :
71 3837 : CONVERT_ARG_CHECKED(JSFunction, f, 0);
72 1279 : return isolate->heap()->ToBoolean(f->shared()->IsApiFunction());
73 : }
74 :
75 :
76 : // Set the native flag on the function.
77 : // This is used to decide if we should transform null and undefined
78 : // into the global object when doing call and apply.
79 0 : RUNTIME_FUNCTION(Runtime_SetNativeFlag) {
80 : SealHandleScope shs(isolate);
81 : DCHECK_EQ(1, args.length());
82 :
83 0 : CONVERT_ARG_CHECKED(Object, object, 0);
84 :
85 0 : if (object->IsJSFunction()) {
86 0 : JSFunction func = JSFunction::cast(object);
87 0 : func->shared()->set_native(true);
88 : }
89 : return ReadOnlyRoots(isolate).undefined_value();
90 : }
91 :
92 :
93 513 : RUNTIME_FUNCTION(Runtime_Call) {
94 513 : HandleScope scope(isolate);
95 : DCHECK_LE(2, args.length());
96 513 : int const argc = args.length() - 2;
97 513 : CONVERT_ARG_HANDLE_CHECKED(Object, target, 0);
98 513 : CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1);
99 1026 : ScopedVector<Handle<Object>> argv(argc);
100 702 : for (int i = 0; i < argc; ++i) {
101 702 : argv[i] = args.at(2 + i);
102 : }
103 1026 : RETURN_RESULT_OR_FAILURE(
104 513 : isolate, Execution::Call(isolate, target, receiver, argc, argv.start()));
105 : }
106 :
107 :
108 1846 : RUNTIME_FUNCTION(Runtime_IsFunction) {
109 : SealHandleScope shs(isolate);
110 : DCHECK_EQ(1, args.length());
111 3692 : CONVERT_ARG_CHECKED(Object, object, 0);
112 3692 : return isolate->heap()->ToBoolean(object->IsFunction());
113 : }
114 :
115 :
116 : } // namespace internal
117 183867 : } // namespace v8
|