1// Copyright 2015 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/**
6 * Implementation for v8-experimental.h.
7 */
8
9#include "src/api-experimental.h"
10
11#include "include/v8.h"
12#include "include/v8-experimental.h"
13#include "src/api.h"
14#include "src/fast-accessor-assembler.h"
15
16namespace {
17
18v8::internal::FastAccessorAssembler* FromApi(
19    v8::experimental::FastAccessorBuilder* builder) {
20  return reinterpret_cast<v8::internal::FastAccessorAssembler*>(builder);
21}
22
23v8::experimental::FastAccessorBuilder* FromInternal(
24    v8::internal::FastAccessorAssembler* fast_accessor_assembler) {
25  return reinterpret_cast<v8::experimental::FastAccessorBuilder*>(
26      fast_accessor_assembler);
27}
28
29}  // namespace
30
31namespace v8 {
32namespace internal {
33namespace experimental {
34
35
36MaybeHandle<Code> BuildCodeFromFastAccessorBuilder(
37    v8::experimental::FastAccessorBuilder* fast_handler) {
38  i::MaybeHandle<i::Code> code;
39  if (fast_handler != nullptr) {
40    auto faa = FromApi(fast_handler);
41    code = faa->Build();
42    CHECK(!code.is_null());
43    delete faa;
44  }
45  return code;
46}
47
48}  // namespace experimental
49}  // namespace internal
50
51
52namespace experimental {
53
54
55FastAccessorBuilder* FastAccessorBuilder::New(Isolate* isolate) {
56  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
57  internal::FastAccessorAssembler* faa =
58      new internal::FastAccessorAssembler(i_isolate);
59  return FromInternal(faa);
60}
61
62
63FastAccessorBuilder::ValueId FastAccessorBuilder::IntegerConstant(
64    int const_value) {
65  return FromApi(this)->IntegerConstant(const_value);
66}
67
68
69FastAccessorBuilder::ValueId FastAccessorBuilder::GetReceiver() {
70  return FromApi(this)->GetReceiver();
71}
72
73
74FastAccessorBuilder::ValueId FastAccessorBuilder::LoadInternalField(
75    ValueId value, int field_no) {
76  return FromApi(this)->LoadInternalField(value, field_no);
77}
78
79
80FastAccessorBuilder::ValueId FastAccessorBuilder::LoadValue(ValueId value_id,
81                                                            int offset) {
82  return FromApi(this)->LoadValue(value_id, offset);
83}
84
85
86FastAccessorBuilder::ValueId FastAccessorBuilder::LoadObject(ValueId value_id,
87                                                             int offset) {
88  return FromApi(this)->LoadObject(value_id, offset);
89}
90
91
92void FastAccessorBuilder::ReturnValue(ValueId value) {
93  FromApi(this)->ReturnValue(value);
94}
95
96
97void FastAccessorBuilder::CheckFlagSetOrReturnNull(ValueId value_id, int mask) {
98  FromApi(this)->CheckFlagSetOrReturnNull(value_id, mask);
99}
100
101
102void FastAccessorBuilder::CheckNotZeroOrReturnNull(ValueId value_id) {
103  FromApi(this)->CheckNotZeroOrReturnNull(value_id);
104}
105
106
107FastAccessorBuilder::LabelId FastAccessorBuilder::MakeLabel() {
108  return FromApi(this)->MakeLabel();
109}
110
111
112void FastAccessorBuilder::SetLabel(LabelId label_id) {
113  FromApi(this)->SetLabel(label_id);
114}
115
116
117void FastAccessorBuilder::CheckNotZeroOrJump(ValueId value_id,
118                                             LabelId label_id) {
119  FromApi(this)->CheckNotZeroOrJump(value_id, label_id);
120}
121
122FastAccessorBuilder::ValueId FastAccessorBuilder::Call(
123    v8::FunctionCallback callback, ValueId value_id) {
124  return FromApi(this)->Call(callback, value_id);
125}
126
127}  // namespace experimental
128}  // namespace v8
129