From 62f20202eb510c27e6f5eb5c7bc1646dc920a61a Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Mon, 16 Sep 2024 17:25:57 +0200 Subject: [PATCH] [spidermonkey] Text.insertBefore modified --- src/ecmascript/spidermonkey/text.cpp | 36 ++++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/ecmascript/spidermonkey/text.cpp b/src/ecmascript/spidermonkey/text.cpp index 60ea0f9b7..5c5434e7f 100644 --- a/src/ecmascript/spidermonkey/text.cpp +++ b/src/ecmascript/spidermonkey/text.cpp @@ -2011,34 +2011,34 @@ text_insertBefore(JSContext *ctx, unsigned int argc, JS::Value *rval) JS::RootedObject hobj(ctx, &args.thisv().toObject()); if (!JS_InstanceOf(ctx, hobj, &text_class, NULL)) { - args.rval().setBoolean(false); - return true; + return false; } dom_node *el = (dom_node *)JS::GetMaybePtrFromReservedSlot(hobj, 0); if (!el) { - args.rval().setUndefined(); - return true; + return false; } - JS::RootedObject next_sibling1(ctx, &args[1].toObject()); - JS::RootedObject child1(ctx, &args[0].toObject()); + dom_node *next_sibling = NULL; + dom_node *child = NULL; - dom_node *next_sibling = (dom_node *)JS::GetMaybePtrFromReservedSlot(next_sibling1, 0); - - if (!next_sibling) { - args.rval().setNull(); - return true; + if (!args[1].isNull()) { + JS::RootedObject next_sibling1(ctx, &args[1].toObject()); + next_sibling = (dom_node *)JS::GetMaybePtrFromReservedSlot(next_sibling1, 0); } - dom_node *child = (dom_node *)JS::GetMaybePtrFromReservedSlot(child1, 0); + if (!args[0].isNull()) { + JS::RootedObject child1(ctx, &args[0].toObject()); + child = (dom_node *)JS::GetMaybePtrFromReservedSlot(child1, 0); + } - dom_exception err; - dom_node *spare; + if (!child) { + return false; + } + dom_node *spare = NULL; + dom_exception err = dom_node_insert_before(el, child, next_sibling, &spare); - err = dom_node_insert_before(el, child, next_sibling, &spare); - if (err != DOM_NO_ERR) { - args.rval().setUndefined(); - return true; + if (err != DOM_NO_ERR || !spare) { + return false; } JSObject *obj = getElement(ctx, spare); dom_node_unref(spare);