v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
runtime-function.cc
Go to the documentation of this file.
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
7#include "src/heap/heap-inl.h" // For ToBoolean. TODO(jkummerow): Drop.
8
9namespace v8 {
10namespace internal {
11
12// TODO(5530): Remove once uses in debug.js are gone.
13RUNTIME_FUNCTION(Runtime_FunctionGetScriptSource) {
14 HandleScope scope(isolate);
15 DCHECK_EQ(1, args.length());
17
18 if (IsJSFunction(*function)) {
20 isolate);
21 if (IsScript(*script)) return Cast<Script>(script)->source();
22 }
23 return ReadOnlyRoots(isolate).undefined_value();
24}
25
26RUNTIME_FUNCTION(Runtime_FunctionGetScriptId) {
27 HandleScope scope(isolate);
28 DCHECK_EQ(1, args.length());
30
31 if (IsJSFunction(*function)) {
33 isolate);
34 if (IsScript(*script)) {
35 return Smi::FromInt(Cast<Script>(script)->id());
36 }
37 }
38 return Smi::FromInt(-1);
39}
40
41RUNTIME_FUNCTION(Runtime_FunctionGetSourceCode) {
42 HandleScope scope(isolate);
43 DCHECK_EQ(1, args.length());
45 if (IsJSFunction(*function)) {
47 Cast<JSFunction>(function)->shared(), isolate);
48 return *SharedFunctionInfo::GetSourceCode(isolate, shared);
49 }
50 return ReadOnlyRoots(isolate).undefined_value();
51}
52
53
54RUNTIME_FUNCTION(Runtime_FunctionGetScriptSourcePosition) {
55 SealHandleScope shs(isolate);
56 DCHECK_EQ(1, args.length());
57
58 auto fun = Cast<JSFunction>(args[0]);
59 int pos = fun->shared()->StartPosition();
60 return Smi::FromInt(pos);
61}
62
63
64RUNTIME_FUNCTION(Runtime_FunctionIsAPIFunction) {
65 SealHandleScope shs(isolate);
66 DCHECK_EQ(1, args.length());
67
68 auto f = Cast<JSFunction>(args[0]);
69 return isolate->heap()->ToBoolean(f->shared()->IsApiFunction());
70}
71
72
73RUNTIME_FUNCTION(Runtime_Call) {
74 HandleScope scope(isolate);
75 DCHECK_LE(2, args.length());
76 int const argc = args.length() - 2;
77 DirectHandle<Object> target = args.at(0);
79 DirectHandleVector<Object> arguments(isolate, argc);
80 for (int i = 0; i < argc; ++i) {
81 arguments[i] = args.at(2 + i);
82 }
83 RETURN_RESULT_OR_FAILURE(isolate, Execution::Call(isolate, target, receiver,
84 base::VectorOf(arguments)));
85}
86
87
88} // namespace internal
89} // namespace v8
SourcePosition pos
V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT MaybeHandle< Object > Call(Isolate *isolate, DirectHandle< Object > callable, DirectHandle< Object > receiver, base::Vector< const DirectHandle< Object > > args)
Definition execution.cc:523
static DirectHandle< Object > GetSourceCode(Isolate *isolate, DirectHandle< SharedFunctionInfo > shared)
static constexpr Tagged< Smi > FromInt(int value)
Definition smi.h:38
#define RUNTIME_FUNCTION(Name)
Definition arguments.h:162
#define RETURN_RESULT_OR_FAILURE(isolate, call)
Definition isolate.h:264
base::Vector< const DirectHandle< Object > > args
Definition execution.cc:74
TNode< Object > receiver
SharedFunctionInfoRef shared
constexpr Vector< T > VectorOf(T *start, size_t size)
Definition vector.h:360
kInterpreterTrampolineOffset script
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
#define DCHECK_LE(v1, v2)
Definition logging.h:490
#define DCHECK_EQ(v1, v2)
Definition logging.h:485