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