• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2019 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/builtins/builtins-proxy-gen.h'
6
7namespace proxy {
8
9// ES #sec-proxy-constructor
10// https://tc39.github.io/ecma262/#sec-proxy-constructor
11transitioning javascript builtin
12ProxyConstructor(
13    js-implicit context: NativeContext, receiver: JSAny, newTarget: JSAny)(
14    target: JSAny, handler: JSAny): JSProxy {
15  try {
16    // 1. If NewTarget is undefined, throw a TypeError exception.
17    if (newTarget == Undefined) {
18      ThrowTypeError(MessageTemplate::kConstructorNotFunction, 'Proxy');
19    }
20
21    // 2. Return ? ProxyCreate(target, handler).
22    // https://tc39.github.io/ecma262/#sec-proxycreate
23    // 1. If Type(target) is not Object, throw a TypeError exception.
24    // 2. If Type(handler) is not Object, throw a TypeError exception.
25    const targetJSReceiver =
26        Cast<JSReceiver>(target) otherwise ThrowProxyNonObject;
27    const handlerJSReceiver =
28        Cast<JSReceiver>(handler) otherwise ThrowProxyNonObject;
29
30    // 5. Let P be a newly created object.
31    // 6. Set P's essential internal methods (except for [[Call]] and
32    //    [[Construct]]) to the definitions specified in 9.5.
33    // 7. If IsCallable(target) is true, then
34    //    a. Set P.[[Call]] as specified in 9.5.12.
35    //    b. If IsConstructor(target) is true, then
36    //       1. Set P.[[Construct]] as specified in 9.5.13.
37    // 8. Set P.[[ProxyTarget]] to target.
38    // 9. Set P.[[ProxyHandler]] to handler.
39    // 10. Return P.
40    return AllocateProxy(targetJSReceiver, handlerJSReceiver);
41  } label ThrowProxyNonObject deferred {
42    ThrowTypeError(MessageTemplate::kProxyNonObject);
43  }
44}
45}
46