 Chromium Code Reviews
 Chromium Code Reviews Issue 1409593002:
  [api] expose API for adding per-context Intrinsics to Templates  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master
    
  
    Issue 1409593002:
  [api] expose API for adding per-context Intrinsics to Templates  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master| Index: src/api-natives.cc | 
| diff --git a/src/api-natives.cc b/src/api-natives.cc | 
| index 051ea4a17b15c16e689673f7804dedb2afde4f0d..64572a6090f83ea26d0d3ba974667d2995d100d0 100644 | 
| --- a/src/api-natives.cc | 
| +++ b/src/api-natives.cc | 
| @@ -148,6 +148,25 @@ class AccessCheckDisableScope { | 
| }; | 
| +Object* GetIntrinsic(Context* context, v8::Intrinsic intrinsic) { | 
| + switch (intrinsic) { | 
| +#define GET_INTRINSIC_VALUE(name, iname) \ | 
| + case v8::k##name: \ | 
| + return context->iname(); | 
| + V8_INTRINSICS_LIST(GET_INTRINSIC_VALUE) | 
| +#undef GET_INTRINSIC_VALUE | 
| + } | 
| + return nullptr; | 
| +} | 
| + | 
| + | 
| +Context* GetCurrentContext(Isolate* isolate) { | 
| 
Toon Verwaest
2015/10/20 15:00:54
This seems unnecessary given that context->iname()
 
caitp (gmail)
2015/10/20 15:38:06
Ok
 | 
| + Context* context = isolate->context(); | 
| + if (context != nullptr) return context->native_context(); | 
| + return nullptr; | 
| +} | 
| + | 
| + | 
| MaybeHandle<JSObject> ConfigureInstance(Isolate* isolate, Handle<JSObject> obj, | 
| Handle<TemplateInfo> data) { | 
| auto property_list = handle(data->property_list(), isolate); | 
| @@ -162,23 +181,41 @@ MaybeHandle<JSObject> ConfigureInstance(Isolate* isolate, Handle<JSObject> obj, | 
| int i = 0; | 
| for (int c = 0; c < data->number_of_properties(); c++) { | 
| auto name = handle(Name::cast(properties.get(i++)), isolate); | 
| - PropertyDetails details(Smi::cast(properties.get(i++))); | 
| - PropertyAttributes attributes = details.attributes(); | 
| - PropertyKind kind = details.kind(); | 
| + auto bit = handle(properties.get(i++), isolate); | 
| + if (bit->IsSmi()) { | 
| + PropertyDetails details(Smi::cast(*bit)); | 
| + PropertyAttributes attributes = details.attributes(); | 
| + PropertyKind kind = details.kind(); | 
| + | 
| + if (kind == kData) { | 
| + auto prop_data = handle(properties.get(i++), isolate); | 
| + | 
| + RETURN_ON_EXCEPTION(isolate, DefineDataProperty(isolate, obj, name, | 
| + prop_data, attributes), | 
| + JSObject); | 
| + } else { | 
| + auto getter = handle(properties.get(i++), isolate); | 
| + auto setter = handle(properties.get(i++), isolate); | 
| + RETURN_ON_EXCEPTION(isolate, | 
| + DefineAccessorProperty(isolate, obj, name, getter, | 
| + setter, attributes), | 
| + JSObject); | 
| + } | 
| + } else { | 
| + // Intrinsic data property --- Get appropriate value from the current | 
| + // context. | 
| + PropertyDetails details(Smi::cast(properties.get(i++))); | 
| + PropertyAttributes attributes = details.attributes(); | 
| + DCHECK_EQ(kData, details.kind()); | 
| - if (kind == kData) { | 
| - auto prop_data = handle(properties.get(i++), isolate); | 
| + v8::Intrinsic intrinsic = | 
| + static_cast<v8::Intrinsic>(Smi::cast(properties.get(i++))->value()); | 
| + auto prop_data = | 
| + handle(GetIntrinsic(GetCurrentContext(isolate), intrinsic), isolate); | 
| RETURN_ON_EXCEPTION(isolate, DefineDataProperty(isolate, obj, name, | 
| prop_data, attributes), | 
| JSObject); | 
| - } else { | 
| - auto getter = handle(properties.get(i++), isolate); | 
| - auto setter = handle(properties.get(i++), isolate); | 
| - RETURN_ON_EXCEPTION(isolate, | 
| - DefineAccessorProperty(isolate, obj, name, getter, | 
| - setter, attributes), | 
| - JSObject); | 
| } | 
| } | 
| return obj; | 
| @@ -377,6 +414,19 @@ void ApiNatives::AddDataProperty(Isolate* isolate, Handle<TemplateInfo> info, | 
| } | 
| +void ApiNatives::AddDataProperty(Isolate* isolate, Handle<TemplateInfo> info, | 
| + Handle<Name> name, v8::Intrinsic intrinsic, | 
| + PropertyAttributes attributes) { | 
| + const int kSize = 4; | 
| + auto value = handle(Smi::FromInt(intrinsic), isolate); | 
| + auto intrinsic_marker = isolate->factory()->true_value(); | 
| + PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell); | 
| + auto details_handle = handle(details.AsSmi(), isolate); | 
| + Handle<Object> data[kSize] = {name, intrinsic_marker, details_handle, value}; | 
| + AddPropertyToPropertyList(isolate, info, kSize, data); | 
| +} | 
| + | 
| + | 
| void ApiNatives::AddAccessorProperty(Isolate* isolate, | 
| Handle<TemplateInfo> info, | 
| Handle<Name> name, Handle<Object> getter, |