Index: src/api-natives.cc |
diff --git a/src/api-natives.cc b/src/api-natives.cc |
index a62c231ceb229586791f2aefa61e924cb19b9390..686626d7658c1847f47e12e0576890db11877ecc 100644 |
--- a/src/api-natives.cc |
+++ b/src/api-natives.cc |
@@ -37,6 +37,25 @@ MaybeHandle<Object> Instantiate(Isolate* isolate, Handle<Object> data, |
} |
+MaybeHandle<JSFunction> InstantiateFunctionOrMaybeDont(Isolate* isolate, |
+ Handle<Object> data) { |
+ DCHECK(data->IsFunctionTemplateInfo() || data->IsJSFunction()); |
+ if (data->IsFunctionTemplateInfo()) { |
+ // A function template needs to be instantiated. |
+ return InstantiateFunction(isolate, |
+ Handle<FunctionTemplateInfo>::cast(data)); |
+#ifdef V8_JS_ACCESSORS |
+ } else if (data->IsJSFunction()) { |
+ // If we already have a proper function, we do not need additional work. |
+ // (This should only happen for JavaScript API accessors.) |
+ return Handle<JSFunction>::cast(data); |
+#endif // V8_JS_ACCESSORS |
+ } else { |
+ UNREACHABLE(); |
+ return MaybeHandle<JSFunction>(); |
+ } |
+} |
+ |
MaybeHandle<Object> DefineAccessorProperty(Isolate* isolate, |
Handle<JSObject> object, |
Handle<Name> name, |
@@ -44,18 +63,14 @@ MaybeHandle<Object> DefineAccessorProperty(Isolate* isolate, |
Handle<Object> setter, |
PropertyAttributes attributes) { |
if (!getter->IsUndefined()) { |
- ASSIGN_RETURN_ON_EXCEPTION( |
- isolate, getter, |
- InstantiateFunction(isolate, |
- Handle<FunctionTemplateInfo>::cast(getter)), |
- Object); |
+ ASSIGN_RETURN_ON_EXCEPTION(isolate, getter, |
+ InstantiateFunctionOrMaybeDont(isolate, getter), |
+ Object); |
} |
if (!setter->IsUndefined()) { |
- ASSIGN_RETURN_ON_EXCEPTION( |
- isolate, setter, |
- InstantiateFunction(isolate, |
- Handle<FunctionTemplateInfo>::cast(setter)), |
- Object); |
+ ASSIGN_RETURN_ON_EXCEPTION(isolate, setter, |
+ InstantiateFunctionOrMaybeDont(isolate, setter), |
+ Object); |
} |
RETURN_ON_EXCEPTION(isolate, JSObject::DefineAccessor(object, name, getter, |
setter, attributes), |
@@ -376,6 +391,22 @@ void ApiNatives::AddAccessorProperty(Isolate* isolate, |
} |
+#ifdef V8_JS_ACCESSORS |
+void ApiNatives::AddAccessorProperty(Isolate* isolate, |
+ Handle<TemplateInfo> info, |
+ Handle<Name> name, |
+ Handle<JSFunction> getter, |
+ Handle<JSFunction> setter, |
+ PropertyAttributes attributes) { |
+ const int kSize = 4; |
+ PropertyDetails details(attributes, ACCESSOR, 0, PropertyCellType::kNoCell); |
+ auto details_handle = handle(details.AsSmi(), isolate); |
+ Handle<Object> data[kSize] = {name, details_handle, getter, setter}; |
+ AddPropertyToPropertyList(isolate, info, kSize, data); |
+} |
+#endif |
+ |
+ |
void ApiNatives::AddNativeDataProperty(Isolate* isolate, |
Handle<TemplateInfo> info, |
Handle<AccessorInfo> property) { |