From f28e752112a74c049c95adf5ae17473492426c30 Mon Sep 17 00:00:00 2001 From: "mrbkap@gmail.com" Date: Fri, 13 Apr 2007 12:20:22 -0700 Subject: [PATCH] Add an API to set aside and restore cx->fp. bug 377090, r=brendan --- js/src/jsapi.c | 28 ++++++++++++++++++++++++++++ js/src/jsapi.h | 19 +++++++++++++++++++ js/src/jsprvtd.h | 1 - js/src/jspubtd.h | 1 + 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/js/src/jsapi.c b/js/src/jsapi.c index 699bd72ba0e..9c02f19e487 100644 --- a/js/src/jsapi.c +++ b/js/src/jsapi.c @@ -4421,6 +4421,34 @@ JS_SetCallReturnValue2(JSContext *cx, jsval v) #endif } +JS_PUBLIC_API(JSStackFrame *) +JS_SaveFrameChain(JSContext *cx) +{ + JSStackFrame *fp; + + fp = cx->fp; + if (!fp) + return fp; + + JS_ASSERT(!fp->dormantNext); + fp->dormantNext = cx->dormantFrameChain; + cx->dormantFrameChain = fp; + cx->fp = NULL; + return fp; +} + +JS_PUBLIC_API(void) +JS_RestoreFrameChain(JSContext *cx, JSStackFrame *fp) +{ + JS_ASSERT(!cx->fp); + if (!fp) + return; + + cx->fp = fp; + cx->dormantFrameChain = fp->dormantNext; + fp->dormantNext = NULL; +} + /************************************************************************/ JS_PUBLIC_API(JSString *) diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 69702926327..82212ce66e1 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -1848,6 +1848,25 @@ JS_IsAssigning(JSContext *cx); extern JS_PUBLIC_API(void) JS_SetCallReturnValue2(JSContext *cx, jsval v); +/* + * Saving and restoring frame chains. + * + * These two functions are used to set aside cx->fp while that frame is + * inactive. After a call to JS_SaveFrameChain, it looks as if there is no + * code running on cx. Before calling JS_RestoreFrameChain, cx's call stack + * must be balanced and all nested calls to JS_SaveFrameChain must have had + * matching JS_RestoreFrameChain calls. + * + * JS_SaveFrameChain deals with cx not having any code running on it. A null + * return does not signify an error and JS_RestoreFrameChain handles null + * frames. + */ +extern JS_PUBLIC_API(JSStackFrame *) +JS_SaveFrameChain(JSContext *cx); + +extern JS_PUBLIC_API(void) +JS_RestoreFrameChain(JSContext *cx, JSStackFrame *fp); + /************************************************************************/ /* diff --git a/js/src/jsprvtd.h b/js/src/jsprvtd.h index 7ac41e0bc57..f71b9a508b0 100644 --- a/js/src/jsprvtd.h +++ b/js/src/jsprvtd.h @@ -116,7 +116,6 @@ typedef struct JSRegExpStatics JSRegExpStatics; typedef struct JSScope JSScope; typedef struct JSScopeOps JSScopeOps; typedef struct JSScopeProperty JSScopeProperty; -typedef struct JSStackFrame JSStackFrame; typedef struct JSStackHeader JSStackHeader; typedef struct JSStringBuffer JSStringBuffer; typedef struct JSSubString JSSubString; diff --git a/js/src/jspubtd.h b/js/src/jspubtd.h index 947249a1b79..4bc54de0af2 100644 --- a/js/src/jspubtd.h +++ b/js/src/jspubtd.h @@ -140,6 +140,7 @@ typedef struct JSXMLObjectOps JSXMLObjectOps; typedef struct JSRuntime JSRuntime; typedef struct JSRuntime JSTaskState; /* XXX deprecated name */ typedef struct JSScript JSScript; +typedef struct JSStackFrame JSStackFrame; typedef struct JSString JSString; typedef struct JSXDRState JSXDRState; typedef struct JSExceptionState JSExceptionState;