• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2018 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@export
6struct Arguments {
7  const frame: FrameWithArguments;
8  const base: RawPtr;
9  // length is the number of arguments without the receiver.
10  const length: intptr;
11  // actual_count is the actual number of arguments on the stack (including the
12  // receiver).
13  const actual_count: intptr;
14}
15
16extern operator '[]' macro GetArgumentValue(Arguments, intptr): JSAny;
17extern macro GetFrameArguments(FrameWithArguments, intptr): Arguments;
18
19struct ArgumentsIterator {
20  macro Next(): Object labels NoMore {
21    if (this.current == this.arguments.length) goto NoMore;
22    return this.arguments[this.current++];
23  }
24  const arguments: Arguments;
25  current: intptr;
26}
27
28struct FrameWithArgumentsInfo {
29  const frame: FrameWithArguments;
30  const argument_count: bint;
31  const formal_parameter_count: bint;
32}
33
34// Calculates and returns the frame pointer, argument count and formal
35// parameter count to be used to access a function's parameters, taking
36// argument adapter frames into account.
37//
38// TODO(danno):
39// This macro is should only be used in builtins that can be called from
40// interpreted or JITted code, not from CSA/Torque builtins (the number of
41// returned formal parameters would be wrong).
42// It is difficult to actually check/dcheck this, since interpreted or JITted
43// frames are StandardFrames, but so are hand-written builtins. Doing that
44// more refined check would be prohibitively expensive.
45macro GetFrameWithArgumentsInfo(implicit context: Context)():
46    FrameWithArgumentsInfo {
47  const frame =
48      Cast<StandardFrame>(LoadParentFramePointer()) otherwise unreachable;
49  const f: JSFunction = frame.function;
50
51  const shared: SharedFunctionInfo = f.shared_function_info;
52  const formalParameterCount: bint = Convert<bint>(Convert<int32>(
53      LoadSharedFunctionInfoFormalParameterCountWithoutReceiver(shared)));
54  // TODO(victorgomes): When removing the v8_disable_arguments_adaptor flag,
55  // FrameWithArgumentsInfo can be simplified, since the frame field already
56  // contains the argument count.
57  const argumentCount: bint = Convert<bint>(frame.argument_count);
58  return FrameWithArgumentsInfo{
59    frame,
60    argument_count: argumentCount,
61    formal_parameter_count: formalParameterCount
62  };
63}
64