arguments.tq 1.97 KB
Newer Older
1 2 3 4
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
@export
6 7 8 9 10 11
struct Arguments {
  const frame: FrameWithArguments;
  const base: RawPtr;
  const length: intptr;
}

12
extern operator '[]' macro GetArgumentValue(Arguments, intptr): JSAny;
13 14 15

extern macro GetFrameArguments(FrameWithArguments, intptr): Arguments;

16 17
namespace arguments {

18
  @export
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
  struct ArgumentsInfo {
    frame: Frame;
    argument_count: bint;
    formal_parameter_count: bint;
  }

  // Calculates and returns the frame pointer, argument count and formal
  // parameter count to be used to access a function's parameters, taking
  // argument adapter frames into account.
  //
  // TODO(danno):
  // This macro is should only be used in builtins that can be called from
  // interpreted or JITted code, not from CSA/Torque builtins (the number of
  // returned formal parameters would be wrong).
  // It is difficult to actually check/assert this, since interpreted or JITted
  // frames are StandardFrames, but so are hand-written builtins. Doing that
  // more refined check would be prohibitively expensive.
36
  @export
37 38
  macro GetArgumentsFrameAndCount(implicit context: Context)(f: JSFunction):
      ArgumentsInfo {
39
    const frame: Frame = LoadParentFramePointer();
40 41 42 43
    assert(frame.function == f);

    const shared: SharedFunctionInfo = f.shared_function_info;
    const formalParameterCount: bint =
44
        Convert<bint>(Convert<int32>(shared.formal_parameter_count));
45
    const argumentCount: bint = formalParameterCount;
46 47 48

    const adaptor: ArgumentsAdaptorFrame =
        Cast<ArgumentsAdaptorFrame>(frame.caller)
49 50 51 52 53
        otherwise return ArgumentsInfo{
      frame,
      argument_count: argumentCount,
      formal_parameter_count: formalParameterCount
    };
54 55

    return ArgumentsInfo{
56 57 58
      frame: adaptor,
      argument_count: Convert<bint>(adaptor.length),
      formal_parameter_count: formalParameterCount
59 60 61
    };
  }
}