mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-04-11 10:28:58 +00:00
avoid dangerous JS_InternString call, and update NodeOps APIs
This commit is contained in:
parent
34b4a81f99
commit
cb97057b16
@ -67,16 +67,30 @@ typedef struct DOM_CharacterData DOM_CharacterData;
|
||||
typedef struct DOM_Text DOM_Text;
|
||||
|
||||
/*
|
||||
* All of these handlers are called _after_ the DOM tree is manipulated,
|
||||
* and will never be called in error conditions (DOM_NOT_CHILD, etc.).
|
||||
* All of these handlers are called before the DOM tree is manipulated, with
|
||||
* before == JS_TRUE, and then again afterwards, with before == JS_FALSE.
|
||||
*
|
||||
* Before:
|
||||
* Handlers should do nothing but check for legality of the operation in
|
||||
* question, and shouldn't make any changes to the underlying document
|
||||
* structure. They should signal an error with DOM_SignalException as
|
||||
* appropriate and return false if the operation should not be permitted.
|
||||
* This handler will never be called if the DOM code can detect that the
|
||||
* operation in question is illegal (DOM_NOT_CHILD, for example).
|
||||
*
|
||||
* After:
|
||||
* The handlers should perform whatever back-end manipulation is appropriate
|
||||
* at this point, or signal an exception and return false.
|
||||
*/
|
||||
struct DOM_NodeOps {
|
||||
JSBool (*insertBefore)(JSContext *cx, DOM_Node *node, DOM_Node *child,
|
||||
DOM_Node *ref);
|
||||
DOM_Node *ref, JSBool before);
|
||||
JSBool (*replaceChild)(JSContext *cx, DOM_Node *node, DOM_Node *child,
|
||||
DOM_Node *old);
|
||||
JSBool (*removeChild) (JSContext *cx, DOM_Node *node, DOM_Node *old);
|
||||
JSBool (*appendChild) (JSContext *cx, DOM_Node *node, DOM_Node *child);
|
||||
DOM_Node *old, JSBool before);
|
||||
JSBool (*removeChild) (JSContext *cx, DOM_Node *node, DOM_Node *old,
|
||||
JSBool before);
|
||||
JSBool (*appendChild) (JSContext *cx, DOM_Node *node, DOM_Node *child,
|
||||
JSBool before);
|
||||
|
||||
/* free up Node-private data */
|
||||
void (*destroyNode) (JSContext *cx, DOM_Node *node);
|
||||
@ -89,17 +103,19 @@ struct DOM_NodeOps {
|
||||
/* stubs */
|
||||
JSBool
|
||||
DOM_InsertBeforeStub(JSContext *cx, DOM_Node *node, DOM_Node *child,
|
||||
DOM_Node *ref);
|
||||
DOM_Node *ref, JSBool before);
|
||||
|
||||
JSBool
|
||||
DOM_ReplaceChildStub(JSContext *cx, DOM_Node *node, DOM_Node *child,
|
||||
DOM_Node *old);
|
||||
DOM_Node *old, JSBool before);
|
||||
|
||||
JSBool
|
||||
DOM_RemoveChildStub(JSContext *cx, DOM_Node *node, DOM_Node *old);
|
||||
DOM_RemoveChildStub(JSContext *cx, DOM_Node *node, DOM_Node *old,
|
||||
JSBool before);
|
||||
|
||||
JSBool
|
||||
DOM_AppendChildStub(JSContext *cx, DOM_Node *node, DOM_Node *child);
|
||||
DOM_AppendChildStub(JSContext *cx, DOM_Node *node, DOM_Node *child,
|
||||
JSBool before);
|
||||
|
||||
void
|
||||
DOM_DestroyNodeStub(JSContext *cx, DOM_Node *node);
|
||||
|
@ -56,27 +56,29 @@ DOM_SignalException(JSContext *cx, DOM_ExceptionCode exception)
|
||||
}
|
||||
|
||||
JSBool
|
||||
DOM_InsertBeforeStub(JSContext *cx, DOM_Node *node,
|
||||
DOM_Node *child, DOM_Node *ref)
|
||||
DOM_InsertBeforeStub(JSContext *cx, DOM_Node *node, DOM_Node *child,
|
||||
DOM_Node *ref, JSBool before)
|
||||
{
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSBool
|
||||
DOM_ReplaceChildStub(JSContext *cx, DOM_Node *node, DOM_Node *child,
|
||||
DOM_Node *old)
|
||||
DOM_Node *old, JSBool before)
|
||||
{
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSBool
|
||||
DOM_RemoveChildStub(JSContext *cx, DOM_Node *node, DOM_Node *old)
|
||||
DOM_RemoveChildStub(JSContext *cx, DOM_Node *node, DOM_Node *old,
|
||||
JSBool before)
|
||||
{
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSBool
|
||||
DOM_AppendChildStub(JSContext *cx, DOM_Node *node, DOM_Node *child)
|
||||
DOM_AppendChildStub(JSContext *cx, DOM_Node *node, DOM_Node *child,
|
||||
JSBool before)
|
||||
{
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
@ -65,7 +65,14 @@ element_getter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
|
||||
if (slot == DOM_ELEMENT_TAGNAME) {
|
||||
JSString *tagName =
|
||||
#ifdef DEBUG_shaver
|
||||
fprintf(stderr, "getting tagName %s\n",
|
||||
element->tagName ? element->tagName : "#tag");
|
||||
JS_InternString(cx, element->tagName ? element->tagName : "#tag");
|
||||
#else
|
||||
JS_NewStringCopyZ(cx,
|
||||
element->tagName ? element->tagName : "#tag");
|
||||
#endif
|
||||
if (!tagName)
|
||||
return JS_FALSE;
|
||||
*vp = STRING_TO_JSVAL(tagName);
|
||||
|
@ -92,8 +92,11 @@ dom_node_getter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
*vp = JSVAL_NULL; /* XXX '#nameless' or some such? */
|
||||
return JS_TRUE;
|
||||
}
|
||||
/* str = JS_InternString(cx, node->name); XXX crashes? */
|
||||
#ifdef DEBUG_shaver_0
|
||||
str = JS_InternString(cx, node->name);
|
||||
#else
|
||||
str = JS_NewStringCopyZ(cx, node->name);
|
||||
#endif
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
*vp = STRING_TO_JSVAL(str);
|
||||
@ -243,7 +246,7 @@ PR_END_MACRO
|
||||
|
||||
static JSBool
|
||||
node_insertBefore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
jsval *vp)
|
||||
jsval *vp)
|
||||
{
|
||||
JSObject *newChild, *refChild;
|
||||
DOM_Node *newNode, *refNode, *node;
|
||||
@ -264,6 +267,8 @@ node_insertBefore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
|
||||
CHECK_LEGAL_CHILD(node, newNode);
|
||||
FAIL_UNLESS_CHILD(node, refNode);
|
||||
if (!node->ops->insertBefore(cx, node, newNode, refNode, JS_TRUE))
|
||||
return JS_FALSE;
|
||||
REMOVE_FROM_TREE(newNode);
|
||||
|
||||
newNode->parent = node;
|
||||
@ -273,7 +278,7 @@ node_insertBefore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
|
||||
refNode->prev_sibling = newNode;
|
||||
|
||||
return node->ops->insertBefore(cx, node, newNode, refNode);
|
||||
return node->ops->insertBefore(cx, node, newNode, refNode, JS_TRUE);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
@ -299,6 +304,8 @@ node_replaceChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
|
||||
CHECK_LEGAL_CHILD(node, newNode);
|
||||
FAIL_UNLESS_CHILD(node, oldNode);
|
||||
if (!node->ops->replaceChild(cx, node, newNode, oldNode, JS_TRUE))
|
||||
return JS_FALSE;
|
||||
REMOVE_FROM_TREE(newNode);
|
||||
|
||||
newNode->parent = node;
|
||||
@ -307,7 +314,7 @@ node_replaceChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
|
||||
oldNode->parent = oldNode->sibling = oldNode->prev_sibling = NULL;
|
||||
|
||||
return node->ops->replaceChild(cx, node, newNode, oldNode);
|
||||
return node->ops->replaceChild(cx, node, newNode, oldNode, JS_FALSE);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
@ -327,9 +334,12 @@ node_removeChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
return JS_TRUE;
|
||||
|
||||
FAIL_UNLESS_CHILD(node, deadNode);
|
||||
if (!node->ops->removeChild(cx, node, deadNode, JS_TRUE))
|
||||
return JS_FALSE;
|
||||
|
||||
REMOVE_FROM_TREE(deadNode);
|
||||
|
||||
return node->ops->removeChild(cx, node, deadNode);
|
||||
return node->ops->removeChild(cx, node, deadNode, JS_FALSE);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
@ -349,6 +359,7 @@ node_appendChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
return JS_TRUE;
|
||||
|
||||
CHECK_LEGAL_CHILD(node, newNode);
|
||||
if (node->ops->appendChild(cx, node, newNode, JS_TRUE))
|
||||
REMOVE_FROM_TREE(newNode);
|
||||
|
||||
newNode->parent = node;
|
||||
@ -363,7 +374,7 @@ node_appendChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
node->child = newNode;
|
||||
}
|
||||
|
||||
return node->ops->appendChild(cx, node, newNode);
|
||||
return node->ops->appendChild(cx, node, newNode, JS_FALSE);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
|
Loading…
x
Reference in New Issue
Block a user