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 
16 namespace {
17 
FromApi(v8::experimental::FastAccessorBuilder * builder)18 v8::internal::FastAccessorAssembler* FromApi(
19     v8::experimental::FastAccessorBuilder* builder) {
20   return reinterpret_cast<v8::internal::FastAccessorAssembler*>(builder);
21 }
22 
FromInternal(v8::internal::FastAccessorAssembler * fast_accessor_assembler)23 v8::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 
31 namespace v8 {
32 namespace internal {
33 namespace experimental {
34 
35 
BuildCodeFromFastAccessorBuilder(v8::experimental::FastAccessorBuilder * fast_handler)36 MaybeHandle<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 
52 namespace experimental {
53 
54 
New(Isolate * isolate)55 FastAccessorBuilder* 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 
IntegerConstant(int const_value)63 FastAccessorBuilder::ValueId FastAccessorBuilder::IntegerConstant(
64     int const_value) {
65   return FromApi(this)->IntegerConstant(const_value);
66 }
67 
68 
GetReceiver()69 FastAccessorBuilder::ValueId FastAccessorBuilder::GetReceiver() {
70   return FromApi(this)->GetReceiver();
71 }
72 
73 
LoadInternalField(ValueId value,int field_no)74 FastAccessorBuilder::ValueId FastAccessorBuilder::LoadInternalField(
75     ValueId value, int field_no) {
76   return FromApi(this)->LoadInternalField(value, field_no);
77 }
78 
LoadInternalFieldUnchecked(ValueId value,int field_no)79 FastAccessorBuilder::ValueId FastAccessorBuilder::LoadInternalFieldUnchecked(
80     ValueId value, int field_no) {
81   return FromApi(this)->LoadInternalFieldUnchecked(value, field_no);
82 }
83 
LoadValue(ValueId value_id,int offset)84 FastAccessorBuilder::ValueId FastAccessorBuilder::LoadValue(ValueId value_id,
85                                                             int offset) {
86   return FromApi(this)->LoadValue(value_id, offset);
87 }
88 
89 
LoadObject(ValueId value_id,int offset)90 FastAccessorBuilder::ValueId FastAccessorBuilder::LoadObject(ValueId value_id,
91                                                              int offset) {
92   return FromApi(this)->LoadObject(value_id, offset);
93 }
94 
ToSmi(ValueId value_id)95 FastAccessorBuilder::ValueId FastAccessorBuilder::ToSmi(ValueId value_id) {
96   return FromApi(this)->ToSmi(value_id);
97 }
98 
ReturnValue(ValueId value)99 void FastAccessorBuilder::ReturnValue(ValueId value) {
100   FromApi(this)->ReturnValue(value);
101 }
102 
103 
CheckFlagSetOrReturnNull(ValueId value_id,int mask)104 void FastAccessorBuilder::CheckFlagSetOrReturnNull(ValueId value_id, int mask) {
105   FromApi(this)->CheckFlagSetOrReturnNull(value_id, mask);
106 }
107 
108 
CheckNotZeroOrReturnNull(ValueId value_id)109 void FastAccessorBuilder::CheckNotZeroOrReturnNull(ValueId value_id) {
110   FromApi(this)->CheckNotZeroOrReturnNull(value_id);
111 }
112 
113 
MakeLabel()114 FastAccessorBuilder::LabelId FastAccessorBuilder::MakeLabel() {
115   return FromApi(this)->MakeLabel();
116 }
117 
118 
SetLabel(LabelId label_id)119 void FastAccessorBuilder::SetLabel(LabelId label_id) {
120   FromApi(this)->SetLabel(label_id);
121 }
122 
Goto(LabelId label_id)123 void FastAccessorBuilder::Goto(LabelId label_id) {
124   FromApi(this)->Goto(label_id);
125 }
126 
CheckNotZeroOrJump(ValueId value_id,LabelId label_id)127 void FastAccessorBuilder::CheckNotZeroOrJump(ValueId value_id,
128                                              LabelId label_id) {
129   FromApi(this)->CheckNotZeroOrJump(value_id, label_id);
130 }
131 
Call(v8::FunctionCallback callback,ValueId value_id)132 FastAccessorBuilder::ValueId FastAccessorBuilder::Call(
133     v8::FunctionCallback callback, ValueId value_id) {
134   return FromApi(this)->Call(callback, value_id);
135 }
136 
137 }  // namespace experimental
138 }  // namespace v8
139