mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
Factor smjs_get_global_object out of init_smjs.
This commit is contained in:
parent
2a0653a9f2
commit
3174c533b0
@ -3,6 +3,6 @@ include $(top_builddir)/Makefile.config
|
||||
|
||||
INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
||||
|
||||
OBJS = smjs.o core.o hooks.o elinks_object.o cache_object.o
|
||||
OBJS = smjs.o core.o global_object.o hooks.o elinks_object.o cache_object.o
|
||||
|
||||
include $(top_srcdir)/Makefile.lib
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "scripting/scripting.h"
|
||||
#include "scripting/smjs/core.h"
|
||||
#include "scripting/smjs/elinks_object.h"
|
||||
#include "scripting/smjs/global_object.h"
|
||||
#include "scripting/smjs/smjs.h"
|
||||
#include "util/string.h"
|
||||
|
||||
@ -97,12 +98,6 @@ smjs_load_hooks(void)
|
||||
void
|
||||
init_smjs(struct module *module)
|
||||
{
|
||||
static const JSClass global_class = {
|
||||
"global", 0,
|
||||
JS_PropertyStub, JS_PropertyStub,
|
||||
JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
|
||||
};
|
||||
JSObject *global_object;
|
||||
|
||||
smjs_rt = JS_NewRuntime(1L * 1024L * 1024L);
|
||||
@ -117,11 +112,7 @@ init_smjs(struct module *module)
|
||||
|
||||
JS_SetErrorReporter(smjs_ctx, error_reporter);
|
||||
|
||||
global_object = JS_NewObject(smjs_ctx, (JSClass *) &global_class,
|
||||
NULL, NULL);
|
||||
if (!global_object) return;
|
||||
|
||||
JS_InitStandardClasses(smjs_ctx, global_object);
|
||||
global_object = smjs_get_global_object();
|
||||
|
||||
smjs_elinks_object = smjs_get_elinks_object(global_object);
|
||||
|
||||
|
39
src/scripting/smjs/global_object.c
Normal file
39
src/scripting/smjs/global_object.c
Normal file
@ -0,0 +1,39 @@
|
||||
/* The global object. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
#include "ecmascript/spidermonkey/util.h"
|
||||
#include "scripting/scripting.h"
|
||||
#include "scripting/smjs/core.h"
|
||||
#include "scripting/smjs/global_object.h"
|
||||
|
||||
|
||||
JSObject *smjs_global_object;
|
||||
|
||||
|
||||
static const JSClass global_class = {
|
||||
"global", 0,
|
||||
JS_PropertyStub, JS_PropertyStub,
|
||||
JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
|
||||
};
|
||||
|
||||
JSObject *
|
||||
smjs_get_global_object(void)
|
||||
{
|
||||
JSObject *jsobj;
|
||||
|
||||
assert(smjs_ctx);
|
||||
|
||||
jsobj = JS_NewObject(smjs_ctx, (JSClass *) &global_class, NULL, NULL);
|
||||
|
||||
if (!jsobj) return NULL;
|
||||
|
||||
JS_InitStandardClasses(smjs_ctx, jsobj);
|
||||
|
||||
return jsobj;
|
||||
}
|
8
src/scripting/smjs/global_object.h
Normal file
8
src/scripting/smjs/global_object.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef EL__SCRIPTING_SMJS_GLOBAL_OBJECT_H
|
||||
#define EL__SCRIPTING_SMJS_GLOBAL_OBJECT_H
|
||||
|
||||
#include "ecmascript/spidermonkey/util.h"
|
||||
|
||||
JSObject *smjs_get_global_object(void);
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user