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" 16 RUNTIME_FUNCTION(Runtime_FunctionGetScriptSource) {
17 HandleScope scope(isolate);
18 DCHECK_EQ(1, args.length());
19 CONVERT_ARG_HANDLE_CHECKED(JSReceiver,
function, 0);
21 if (function->IsJSFunction()) {
22 Handle<Object> script(
23 Handle<JSFunction>::cast(
function)->shared()->script(), isolate);
24 if (script->IsScript())
return Handle<Script>::cast(script)->source();
26 return ReadOnlyRoots(isolate).undefined_value();
29 RUNTIME_FUNCTION(Runtime_FunctionGetScriptId) {
30 HandleScope scope(isolate);
31 DCHECK_EQ(1, args.length());
32 CONVERT_ARG_HANDLE_CHECKED(JSReceiver,
function, 0);
34 if (function->IsJSFunction()) {
35 Handle<Object> script(
36 Handle<JSFunction>::cast(
function)->shared()->script(), isolate);
37 if (script->IsScript()) {
38 return Smi::FromInt(Handle<Script>::cast(script)->
id());
41 return Smi::FromInt(-1);
44 RUNTIME_FUNCTION(Runtime_FunctionGetSourceCode) {
45 HandleScope scope(isolate);
46 DCHECK_EQ(1, args.length());
47 CONVERT_ARG_HANDLE_CHECKED(JSReceiver,
function, 0);
48 if (function->IsJSFunction()) {
49 Handle<SharedFunctionInfo> shared(
50 Handle<JSFunction>::cast(
function)->shared(), isolate);
51 return *SharedFunctionInfo::GetSourceCode(shared);
53 return ReadOnlyRoots(isolate).undefined_value();
57 RUNTIME_FUNCTION(Runtime_FunctionGetScriptSourcePosition) {
58 SealHandleScope shs(isolate);
59 DCHECK_EQ(1, args.length());
61 CONVERT_ARG_CHECKED(JSFunction, fun, 0);
62 int pos = fun->shared()->StartPosition();
63 return Smi::FromInt(pos);
67 RUNTIME_FUNCTION(Runtime_FunctionIsAPIFunction) {
68 SealHandleScope shs(isolate);
69 DCHECK_EQ(1, args.length());
71 CONVERT_ARG_CHECKED(JSFunction, f, 0);
72 return isolate->heap()->ToBoolean(f->shared()->IsApiFunction());
79 RUNTIME_FUNCTION(Runtime_SetNativeFlag) {
80 SealHandleScope shs(isolate);
81 DCHECK_EQ(1, args.length());
83 CONVERT_ARG_CHECKED(Object,
object, 0);
85 if (object->IsJSFunction()) {
86 JSFunction* func = JSFunction::cast(
object);
87 func->shared()->set_native(
true);
89 return ReadOnlyRoots(isolate).undefined_value();
93 RUNTIME_FUNCTION(Runtime_Call) {
94 HandleScope scope(isolate);
95 DCHECK_LE(2, args.length());
96 int const argc = args.length() - 2;
97 CONVERT_ARG_HANDLE_CHECKED(Object, target, 0);
98 CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 1);
99 ScopedVector<Handle<Object>> argv(argc);
100 for (
int i = 0;
i < argc; ++
i) {
101 argv[
i] = args.at(2 +
i);
103 RETURN_RESULT_OR_FAILURE(
104 isolate, Execution::Call(isolate, target, receiver, argc, argv.start()));
108 RUNTIME_FUNCTION(Runtime_IsFunction) {
109 SealHandleScope shs(isolate);
110 DCHECK_EQ(1, args.length());
111 CONVERT_ARG_CHECKED(Object,
object, 0);
112 return isolate->heap()->ToBoolean(object->IsFunction());