runtime-proxy.cc 4.16 KB
Newer Older
1 2 3 4
// Copyright 2014 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
#include "src/runtime/runtime-utils.h"
6

7 8
#include "src/execution/arguments-inl.h"
#include "src/execution/isolate-inl.h"
9
#include "src/heap/factory.h"
10
#include "src/heap/heap-inl.h"  // For ToBoolean. TODO(jkummerow): Drop.
11
#include "src/logging/counters.h"
12
#include "src/objects/elements.h"
13
#include "src/objects/objects-inl.h"
14 15 16 17

namespace v8 {
namespace internal {

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
RUNTIME_FUNCTION(Runtime_IsJSProxy) {
  SealHandleScope shs(isolate);
  DCHECK_EQ(1, args.length());
  CONVERT_ARG_CHECKED(Object, obj, 0);
  return isolate->heap()->ToBoolean(obj.IsJSProxy());
}

RUNTIME_FUNCTION(Runtime_JSProxyGetHandler) {
  SealHandleScope shs(isolate);
  DCHECK_EQ(1, args.length());
  CONVERT_ARG_CHECKED(JSProxy, proxy, 0);
  return proxy.handler();
}

RUNTIME_FUNCTION(Runtime_JSProxyGetTarget) {
  SealHandleScope shs(isolate);
  DCHECK_EQ(1, args.length());
  CONVERT_ARG_CHECKED(JSProxy, proxy, 0);
  return proxy.target();
}
38

39 40 41
RUNTIME_FUNCTION(Runtime_GetPropertyWithReceiver) {
  HandleScope scope(isolate);

42
  DCHECK_EQ(4, args.length());
43
  CONVERT_ARG_HANDLE_CHECKED(JSReceiver, holder, 0);
44
  CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
45
  CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 2);
46 47 48 49
  // TODO(mythria): Remove the on_non_existent parameter to this function. This
  // should only be called when getting named properties on receiver. This
  // doesn't handle the global variable loads.
#ifdef DEBUG
50
  CONVERT_ARG_HANDLE_CHECKED(Smi, on_non_existent, 3);
51 52 53
  DCHECK_NE(static_cast<OnNonExistent>(on_non_existent->value()),
            OnNonExistent::kThrowReferenceError);
#endif
54

55
  bool success = false;
56
  PropertyKey lookup_key(isolate, key, &success);
57 58
  if (!success) {
    DCHECK(isolate->has_pending_exception());
59
    return ReadOnlyRoots(isolate).exception();
60
  }
61
  LookupIterator it(isolate, receiver, lookup_key, holder);
62

63
  RETURN_RESULT_OR_FAILURE(isolate, Object::GetProperty(&it));
64 65
}

66
RUNTIME_FUNCTION(Runtime_SetPropertyWithReceiver) {
67 68
  HandleScope scope(isolate);

69
  DCHECK_EQ(4, args.length());
70
  CONVERT_ARG_HANDLE_CHECKED(JSReceiver, holder, 0);
71
  CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
72 73 74
  CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
  CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 3);

75
  bool success = false;
76
  PropertyKey lookup_key(isolate, key, &success);
77 78
  if (!success) {
    DCHECK(isolate->has_pending_exception());
79
    return ReadOnlyRoots(isolate).exception();
80
  }
81
  LookupIterator it(isolate, receiver, lookup_key, holder);
82 83
  Maybe<bool> result =
      Object::SetSuperProperty(&it, value, StoreOrigin::kMaybeKeyed);
84
  MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception());
85 86 87 88 89 90 91
  return *isolate->factory()->ToBoolean(result.FromJust());
}

RUNTIME_FUNCTION(Runtime_CheckProxyGetSetTrapResult) {
  HandleScope scope(isolate);

  DCHECK_EQ(4, args.length());
92 93 94
  CONVERT_ARG_HANDLE_CHECKED(Name, name, 0);
  CONVERT_ARG_HANDLE_CHECKED(JSReceiver, target, 1);
  CONVERT_ARG_HANDLE_CHECKED(Object, trap_result, 2);
95
  CONVERT_NUMBER_CHECKED(int64_t, access_kind, Int64, args[3]);
96

97 98 99
  RETURN_RESULT_OR_FAILURE(isolate, JSProxy::CheckGetSetTrapResult(
                                        isolate, name, target, trap_result,
                                        JSProxy::AccessKind(access_kind)));
100 101
}

102
RUNTIME_FUNCTION(Runtime_CheckProxyHasTrapResult) {
103 104 105 106 107 108
  HandleScope scope(isolate);

  DCHECK_EQ(2, args.length());
  CONVERT_ARG_HANDLE_CHECKED(Name, name, 0);
  CONVERT_ARG_HANDLE_CHECKED(JSReceiver, target, 1);

109
  Maybe<bool> result = JSProxy::CheckHasTrap(isolate, name, target);
110
  if (!result.IsJust()) return ReadOnlyRoots(isolate).exception();
111
  return isolate->heap()->ToBoolean(result.FromJust());
112 113
}

114 115 116 117 118 119 120 121 122 123 124 125
RUNTIME_FUNCTION(Runtime_CheckProxyDeleteTrapResult) {
  HandleScope scope(isolate);

  DCHECK_EQ(2, args.length());
  CONVERT_ARG_HANDLE_CHECKED(Name, name, 0);
  CONVERT_ARG_HANDLE_CHECKED(JSReceiver, target, 1);

  Maybe<bool> result = JSProxy::CheckDeleteTrap(isolate, name, target);
  if (!result.IsJust()) return ReadOnlyRoots(isolate).exception();
  return isolate->heap()->ToBoolean(result.FromJust());
}

126 127
}  // namespace internal
}  // namespace v8