Bug 887016 - Part 4: Add GetOwnNativeGetterPure. r=jandem
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -2423,16 +2423,40 @@ js::GetGetterPure(ExclusiveContext* cx,
return true;
}
return pobj->isNative() &&
NativeGetGetterPureInline(&pobj->as<NativeObject>(), shape, fp);
}
bool
+js::GetOwnNativeGetterPure(JSContext* cx, JSObject* obj, jsid id, JSNative* native)
+{
+ JS::AutoCheckCannotGC nogc;
+ *native = nullptr;
+ Shape* shape;
+ if (!LookupOwnPropertyPure(cx, obj, id, &shape))
+ return false;
+
+ if (!shape || IsImplicitDenseOrTypedArrayElement(shape) || !shape->hasGetterObject())
+ return true;
+
+ JSObject* getterObj = shape->getterObject();
+ if (!getterObj->is<JSFunction>())
+ return true;
+
+ JSFunction* getter = &getterObj->as<JSFunction>();
+ if (!getter->isNative())
+ return true;
+
+ *native = getter->native();
+ return true;
+}
+
+bool
JSObject::reportReadOnly(JSContext* cx, jsid id, unsigned report)
{
RootedValue val(cx, IdToValue(id));
return ReportValueErrorFlags(cx, report, JSMSG_READ_ONLY,
JSDVG_IGNORE_STACK, val, nullptr,
nullptr, nullptr);
}
--- a/js/src/jsobj.h
+++ b/js/src/jsobj.h
@@ -1221,16 +1221,19 @@ LookupOwnPropertyPure(ExclusiveContext*
bool
GetPropertyPure(ExclusiveContext* cx, JSObject* obj, jsid id, Value* vp);
bool
GetGetterPure(ExclusiveContext* cx, JSObject* obj, jsid id, JSFunction** fp);
bool
+GetOwnNativeGetterPure(JSContext* cx, JSObject* obj, jsid id, JSNative* native);
+
+bool
GetOwnPropertyDescriptor(JSContext* cx, HandleObject obj, HandleId id,
MutableHandle<PropertyDescriptor> desc);
bool
GetOwnPropertyDescriptor(JSContext* cx, HandleObject obj, HandleId id, MutableHandleValue vp);
/*
* ES6 draft rev 32 (2015 Feb 2) 6.2.4.4 FromPropertyDescriptor(Desc).