Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/api-natives.cc

Issue 1409593002: [api] expose API for adding per-context Intrinsics to Templates (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix bot failure Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/api-natives.h ('k') | src/objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api-natives.h" 5 #include "src/api-natives.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/isolate-inl.h" 8 #include "src/isolate-inl.h"
9 #include "src/lookup.h" 9 #include "src/lookup.h"
10 #include "src/messages.h" 10 #include "src/messages.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 141 }
142 } 142 }
143 143
144 private: 144 private:
145 Isolate* isolate_; 145 Isolate* isolate_;
146 const bool disabled_; 146 const bool disabled_;
147 Handle<JSObject> obj_; 147 Handle<JSObject> obj_;
148 }; 148 };
149 149
150 150
151 Object* GetIntrinsic(Isolate* isolate, v8::Intrinsic intrinsic) {
152 Handle<Context> native_context = isolate->native_context();
153 DCHECK(!native_context.is_null());
154 switch (intrinsic) {
155 #define GET_INTRINSIC_VALUE(name, iname) \
156 case v8::k##name: \
157 return native_context->iname();
158 V8_INTRINSICS_LIST(GET_INTRINSIC_VALUE)
159 #undef GET_INTRINSIC_VALUE
160 }
161 return nullptr;
162 }
163
164
151 MaybeHandle<JSObject> ConfigureInstance(Isolate* isolate, Handle<JSObject> obj, 165 MaybeHandle<JSObject> ConfigureInstance(Isolate* isolate, Handle<JSObject> obj,
152 Handle<TemplateInfo> data) { 166 Handle<TemplateInfo> data) {
153 auto property_list = handle(data->property_list(), isolate); 167 auto property_list = handle(data->property_list(), isolate);
154 if (property_list->IsUndefined()) return obj; 168 if (property_list->IsUndefined()) return obj;
155 // TODO(dcarney): just use a FixedArray here. 169 // TODO(dcarney): just use a FixedArray here.
156 NeanderArray properties(property_list); 170 NeanderArray properties(property_list);
157 if (properties.length() == 0) return obj; 171 if (properties.length() == 0) return obj;
158 HandleScope scope(isolate); 172 HandleScope scope(isolate);
159 // Disable access checks while instantiating the object. 173 // Disable access checks while instantiating the object.
160 AccessCheckDisableScope access_check_scope(isolate, obj); 174 AccessCheckDisableScope access_check_scope(isolate, obj);
161 175
162 int i = 0; 176 int i = 0;
163 for (int c = 0; c < data->number_of_properties(); c++) { 177 for (int c = 0; c < data->number_of_properties(); c++) {
164 auto name = handle(Name::cast(properties.get(i++)), isolate); 178 auto name = handle(Name::cast(properties.get(i++)), isolate);
165 PropertyDetails details(Smi::cast(properties.get(i++))); 179 auto bit = handle(properties.get(i++), isolate);
166 PropertyAttributes attributes = details.attributes(); 180 if (bit->IsSmi()) {
167 PropertyKind kind = details.kind(); 181 PropertyDetails details(Smi::cast(*bit));
182 PropertyAttributes attributes = details.attributes();
183 PropertyKind kind = details.kind();
168 184
169 if (kind == kData) { 185 if (kind == kData) {
170 auto prop_data = handle(properties.get(i++), isolate); 186 auto prop_data = handle(properties.get(i++), isolate);
187
188 RETURN_ON_EXCEPTION(isolate, DefineDataProperty(isolate, obj, name,
189 prop_data, attributes),
190 JSObject);
191 } else {
192 auto getter = handle(properties.get(i++), isolate);
193 auto setter = handle(properties.get(i++), isolate);
194 RETURN_ON_EXCEPTION(isolate,
195 DefineAccessorProperty(isolate, obj, name, getter,
196 setter, attributes),
197 JSObject);
198 }
199 } else {
200 // Intrinsic data property --- Get appropriate value from the current
201 // context.
202 PropertyDetails details(Smi::cast(properties.get(i++)));
203 PropertyAttributes attributes = details.attributes();
204 DCHECK_EQ(kData, details.kind());
205
206 v8::Intrinsic intrinsic =
207 static_cast<v8::Intrinsic>(Smi::cast(properties.get(i++))->value());
208 auto prop_data = handle(GetIntrinsic(isolate, intrinsic), isolate);
171 209
172 RETURN_ON_EXCEPTION(isolate, DefineDataProperty(isolate, obj, name, 210 RETURN_ON_EXCEPTION(isolate, DefineDataProperty(isolate, obj, name,
173 prop_data, attributes), 211 prop_data, attributes),
174 JSObject); 212 JSObject);
175 } else {
176 auto getter = handle(properties.get(i++), isolate);
177 auto setter = handle(properties.get(i++), isolate);
178 RETURN_ON_EXCEPTION(isolate,
179 DefineAccessorProperty(isolate, obj, name, getter,
180 setter, attributes),
181 JSObject);
182 } 213 }
183 } 214 }
184 return obj; 215 return obj;
185 } 216 }
186 217
187 218
188 MaybeHandle<JSObject> InstantiateObject(Isolate* isolate, 219 MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
189 Handle<ObjectTemplateInfo> data) { 220 Handle<ObjectTemplateInfo> data) {
190 // Enter a new scope. Recursion could otherwise create a lot of handles. 221 // Enter a new scope. Recursion could otherwise create a lot of handles.
191 HandleScope scope(isolate); 222 HandleScope scope(isolate);
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 Handle<Name> name, Handle<Object> value, 401 Handle<Name> name, Handle<Object> value,
371 PropertyAttributes attributes) { 402 PropertyAttributes attributes) {
372 const int kSize = 3; 403 const int kSize = 3;
373 PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell); 404 PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell);
374 auto details_handle = handle(details.AsSmi(), isolate); 405 auto details_handle = handle(details.AsSmi(), isolate);
375 Handle<Object> data[kSize] = {name, details_handle, value}; 406 Handle<Object> data[kSize] = {name, details_handle, value};
376 AddPropertyToPropertyList(isolate, info, kSize, data); 407 AddPropertyToPropertyList(isolate, info, kSize, data);
377 } 408 }
378 409
379 410
411 void ApiNatives::AddDataProperty(Isolate* isolate, Handle<TemplateInfo> info,
412 Handle<Name> name, v8::Intrinsic intrinsic,
413 PropertyAttributes attributes) {
414 const int kSize = 4;
415 auto value = handle(Smi::FromInt(intrinsic), isolate);
416 auto intrinsic_marker = isolate->factory()->true_value();
417 PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell);
418 auto details_handle = handle(details.AsSmi(), isolate);
419 Handle<Object> data[kSize] = {name, intrinsic_marker, details_handle, value};
420 AddPropertyToPropertyList(isolate, info, kSize, data);
421 }
422
423
380 void ApiNatives::AddAccessorProperty(Isolate* isolate, 424 void ApiNatives::AddAccessorProperty(Isolate* isolate,
381 Handle<TemplateInfo> info, 425 Handle<TemplateInfo> info,
382 Handle<Name> name, Handle<Object> getter, 426 Handle<Name> name, Handle<Object> getter,
383 Handle<Object> setter, 427 Handle<Object> setter,
384 PropertyAttributes attributes) { 428 PropertyAttributes attributes) {
385 #ifdef V8_JS_ACCESSORS 429 #ifdef V8_JS_ACCESSORS
386 DCHECK(getter.is_null() || getter->IsFunctionTemplateInfo() || 430 DCHECK(getter.is_null() || getter->IsFunctionTemplateInfo() ||
387 getter->IsJSFunction()); 431 getter->IsJSFunction());
388 DCHECK(setter.is_null() || setter->IsFunctionTemplateInfo() || 432 DCHECK(setter.is_null() || setter->IsFunctionTemplateInfo() ||
389 setter->IsJSFunction()); 433 setter->IsJSFunction());
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 Handle<AccessorInfo> accessor(AccessorInfo::cast(array->get(i))); 630 Handle<AccessorInfo> accessor(AccessorInfo::cast(array->get(i)));
587 JSObject::SetAccessor(result, accessor).Assert(); 631 JSObject::SetAccessor(result, accessor).Assert();
588 } 632 }
589 633
590 DCHECK(result->shared()->IsApiFunction()); 634 DCHECK(result->shared()->IsApiFunction());
591 return result; 635 return result;
592 } 636 }
593 637
594 } // namespace internal 638 } // namespace internal
595 } // namespace v8 639 } // namespace v8
OLDNEW
« no previous file with comments | « src/api-natives.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698