static int qjs_xml_node_define_own_property(JSContext *cx, JSValueConst obj,
JSAtom atom, JSValueConst value, JSValueConst getter, JSValueConst setter,
int flags);
+static int qjs_xml_node_property_modify(JSContext *cx, JSValueConst obj,
+ JSAtom atom, JSValueConst value, int delete);
static JSValue qjs_xml_node_add_child(JSContext *cx, JSValueConst this_val,
int argc, JSValueConst *argv);
static JSValue qjs_xml_node_remove_children(JSContext *cx,
static int
qjs_xml_node_tag_modify(JSContext *cx, JSValue obj, njs_str_t *name,
- JSValue setval)
+ int delete)
{
xmlNode *node;
qjs_xml_node_t *current;
return -1;
}
- if (!JS_IsNullOrUndefined(setval)) {
+ if (!delete) {
JS_ThrowTypeError(cx, "XMLNode.$tag$xxx is not assignable, "
"use addChild() or node.$tags = [node1, node2, ..] "
"syntax");
qjs_xml_node_set_property(JSContext *cx, JSValueConst obj, JSAtom atom,
JSValueConst value, JSValueConst receiver, int flags)
{
- return qjs_xml_node_define_own_property(cx, obj, atom, value,
- JS_UNDEFINED, JS_UNDEFINED, flags);
+ return qjs_xml_node_property_modify(cx, obj, atom, value, 0);
}
static int
qjs_xml_node_delete_property(JSContext *cx, JSValueConst obj, JSAtom prop)
{
- return qjs_xml_node_define_own_property(cx, obj, prop, JS_UNDEFINED,
- JS_UNDEFINED, JS_UNDEFINED,
- JS_PROP_THROW);
+ return qjs_xml_node_property_modify(cx, obj, prop, JS_UNDEFINED, 1);
}
static int
qjs_xml_node_define_own_property(JSContext *cx, JSValueConst obj, JSAtom atom,
JSValueConst value, JSValueConst getter, JSValueConst setter, int flags)
+{
+ return qjs_xml_node_property_modify(cx, obj, atom, value, 0);
+}
+
+
+static int
+qjs_xml_node_property_modify(JSContext *cx, JSValueConst obj, JSAtom atom,
+ JSValueConst value, int delete)
{
int rc;
njs_str_t name, nm;
nm.start = name.start + njs_length("$tag$");
nm.length = name.length - njs_length("$tag$");
- rc = qjs_xml_node_tag_modify(cx, obj, &nm, value);
+ rc = qjs_xml_node_tag_modify(cx, obj, &nm, delete);
JS_FreeCString(cx, (char *) name.start);
}
}
- rc = qjs_xml_node_tag_modify(cx, obj, &name, value);
+ rc = qjs_xml_node_tag_modify(cx, obj, &name, delete);
JS_FreeCString(cx, (char *) name.start);
return rc;
name.length = 0;
}
- rc = qjs_xml_node_tag_modify(cx, this_val, &name, JS_UNDEFINED);
+ rc = qjs_xml_node_tag_modify(cx, this_val, &name, 1);
if (name.start != NULL) {
JS_FreeCString(cx, (char *) name.start);
throw Error('unexpected exception');
},
expected: 'OK' },
+ { get: (doc) => {
+ try {
+ doc.note.$tag$to = null;
+ } catch (e) {
+ return [e instanceof TypeError, doc.note.to.$text].toString();
+ }
+
+ return 'missing exception';
+ },
+ expected: 'true,Tove' },
+ { get: (doc) => {
+ try {
+ doc.note.$tag$to = undefined;
+ } catch (e) {
+ return [e instanceof TypeError, doc.note.to.$text].toString();
+ }
+
+ return 'missing exception';
+ },
+ expected: 'true,Tove' },
+ { get: (doc) => {
+ try {
+ delete doc.note.$tags$to;
+ } catch (e) {
+ return [e instanceof TypeError,
+ doc.note.$tags$to.length].toString();
+ }
+
+ return 'missing exception';
+ },
+ expected: 'true,1' },
{ doc: `<root><a>A</a><b>B</b><c>C</c><a>D</a></root>`,
get: (doc) => {
let b = doc.root.b;