mirror of
https://github.com/rkd77/elinks.git
synced 2025-06-30 22:19:29 -04:00
[spidermonkey] Document constructor
There were some issues with document constructor, so separate object Document.
This commit is contained in:
parent
4e13f17d82
commit
dc74e338d1
@ -259,7 +259,7 @@ void *
|
||||
spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
{
|
||||
JSContext *ctx;
|
||||
JSObject *console_obj, *document_obj, /* *forms_obj,*/ *history_obj,
|
||||
JSObject *console_obj, *document_obj, *Document_obj, /* *forms_obj,*/ *history_obj,
|
||||
*statusbar_obj, *menubar_obj, *navigator_obj, *node_obj, *localstorage_obj, *screen_obj,
|
||||
*xhr_obj, *event_obj, *keyboardEvent_obj, *messageEvent_obj, *customEvent_obj,
|
||||
*url_obj, *urlSearchParams_obj, *domparser_obj, *image_obj;
|
||||
@ -502,6 +502,15 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
goto release_and_fail;
|
||||
}
|
||||
|
||||
Document_obj = spidermonkey_InitClass(ctx, global, NULL,
|
||||
&document_class, Document_constructor, 0,
|
||||
document_props,
|
||||
document_funcs,
|
||||
NULL, NULL, "Document");
|
||||
if (!Document_obj) {
|
||||
goto release_and_fail;
|
||||
}
|
||||
|
||||
#if 1
|
||||
// Register a hook in order to provide modules
|
||||
JS::SetModuleResolveHook(JS_GetRuntime(ctx), ExampleResolveHook);
|
||||
|
@ -2462,3 +2462,43 @@ initDocument(JSContext *ctx, struct ecmascript_interpreter *interpreter, JSObjec
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
Document_constructor(JSContext* ctx, unsigned argc, JS::Value* vp)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
JS::RootedObject newObj(ctx, JS_NewObjectForConstructor(ctx, &document_class, args));
|
||||
|
||||
if (!newObj) {
|
||||
return false;
|
||||
}
|
||||
struct string str;
|
||||
|
||||
if (!init_string(&str)) {
|
||||
return false;
|
||||
}
|
||||
add_to_string(&str, "<!doctype html>\n<html><head></head><body></body></html>");
|
||||
void *doc = document_parse_text("utf-8", str.source, str.length);
|
||||
done_string(&str);
|
||||
|
||||
struct document_private *doc_private = (struct document_private *)mem_calloc(1, sizeof(*doc_private));
|
||||
|
||||
if (!doc_private) {
|
||||
return false;
|
||||
}
|
||||
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||
doc_private->interpreter = interpreter;
|
||||
doc_private->thisval = newObj;
|
||||
doc_private->doc = (dom_document *)doc;
|
||||
init_list(doc_private->listeners);
|
||||
doc_private->ref_count = 1;
|
||||
dom_node_ref(doc);
|
||||
JS::SetReservedSlot(newObj, 0, JS::PrivateValue(doc));
|
||||
JS::SetReservedSlot(newObj, 1, JS::PrivateValue(doc_private));
|
||||
args.rval().setObject(*newObj);
|
||||
return true;
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
#ifndef EL__JS_SPIDERMONKEY_DOCUMENT_H
|
||||
#define EL__JS_SPIDERMONKEY_DOCUMENT_H
|
||||
|
||||
@ -12,6 +11,7 @@ extern JSPropertySpec document_props[];
|
||||
|
||||
JSObject *getDocument(JSContext *ctx, void *doc);
|
||||
JSObject *getDoctype(JSContext *ctx, void *node);
|
||||
bool Document_constructor(JSContext* ctx, unsigned argc, JS::Value* vp);
|
||||
|
||||
bool initDocument(JSContext *ctx, struct ecmascript_interpreter *interpreter, JSObject *document_obj, void *doc);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user