diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index fc013c14cb..3ce22113ed 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -4771,6 +4771,20 @@ JS::GetScriptPrivate(JSScript* script) return script->scriptSourceUnwrap().canonicalPrivate(); } +JS_PUBLIC_API(JS::Value) +JS::GetScriptedCallerPrivate(JSContext* cx) +{ + AssertHeapIsIdle(cx); + CHECK_REQUEST(cx); + + NonBuiltinFrameIter iter(cx, cx->compartment()->principals()); + if (iter.done() || !iter.hasScript()) { + return UndefinedValue(); + } + + return FindScriptOrModulePrivateForScript(iter.script()); +} + JS_PUBLIC_API(JS::ScriptPrivateFinalizeHook) JS::GetScriptPrivateFinalizeHook(JSContext* cx) { diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 2714533354..b4ffd52c6f 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -4410,6 +4410,13 @@ SetScriptPrivate(JSScript* script, const JS::Value& value); extern JS_PUBLIC_API(JS::Value) GetScriptPrivate(JSScript* script); +/* + * Return the private value associated with currently executing script or + * module, or undefined if there is no such script. + */ +extern JS_PUBLIC_API(JS::Value) +GetScriptedCallerPrivate(JSContext* cx); + /** * A hook that's called whenever a script or module which has a private value * set with SetScriptPrivate() or SetModulePrivate() is finalized. This can be