mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[mozjs38] ELinks is compilable, was not heavily tested.
This commit is contained in:
parent
ca24054cc6
commit
01c511f52d
@ -612,11 +612,11 @@ case "$with_spidermonkey" in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
for package in mozjs-31; do
|
for package in mozjs-38; do
|
||||||
if test -n "$CONFIG_SPIDERMONKEY"; then
|
if test -n "$CONFIG_SPIDERMONKEY"; then
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
AC_MSG_CHECKING([for SpiderMonkey (mozjs-31) in pkg-config $package])
|
AC_MSG_CHECKING([for SpiderMonkey (mozjs-38) in pkg-config $package])
|
||||||
if $PKG_CONFIG --cflags --libs $package > /dev/null 2>&AS_MESSAGE_LOG_FD; then
|
if $PKG_CONFIG --cflags --libs $package > /dev/null 2>&AS_MESSAGE_LOG_FD; then
|
||||||
SPIDERMONKEY_LIBS="$($PKG_CONFIG --libs $package)"
|
SPIDERMONKEY_LIBS="$($PKG_CONFIG --libs $package)"
|
||||||
SPIDERMONKEY_CFLAGS="$($PKG_CONFIG --cflags $package)"
|
SPIDERMONKEY_CFLAGS="$($PKG_CONFIG --cflags $package)"
|
||||||
|
@ -271,7 +271,7 @@ if conf_data.get('CONFIG_BZIP2')
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
if conf_data.get('CONFIG_ECMASCRIPT')
|
if conf_data.get('CONFIG_ECMASCRIPT')
|
||||||
mozjsdeps = dependency('mozjs-24')
|
mozjsdeps = dependency('mozjs-38')
|
||||||
deps += mozjsdeps
|
deps += mozjsdeps
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ spidermonkey_runtime_addref(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
spidermonkey_runtime = JS_NewRuntime(4L * 1024L * 1024L, JS_USE_HELPER_THREADS);
|
spidermonkey_runtime = JS_NewRuntime(4L * 1024L * 1024L);
|
||||||
if (!spidermonkey_runtime) return 0;
|
if (!spidermonkey_runtime) return 0;
|
||||||
|
|
||||||
spidermonkey_empty_context = JS_NewContext(spidermonkey_runtime,
|
spidermonkey_empty_context = JS_NewContext(spidermonkey_runtime,
|
||||||
|
@ -69,7 +69,7 @@ static inline unsigned char *
|
|||||||
jsval_to_string(JSContext *ctx, jsval *vp)
|
jsval_to_string(JSContext *ctx, jsval *vp)
|
||||||
{
|
{
|
||||||
JS::RootedValue r_vp(ctx, *vp);
|
JS::RootedValue r_vp(ctx, *vp);
|
||||||
JSString *str = JS::ToString(ctx, r_vp);
|
JSString *str = r_vp.toString();
|
||||||
|
|
||||||
return empty_string_or_(JS_EncodeString(ctx, str));
|
return empty_string_or_(JS_EncodeString(ctx, str));
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
|
|||||||
JSAutoRequest ar(ctx);
|
JSAutoRequest ar(ctx);
|
||||||
JS_SetContextPrivate(ctx, interpreter);
|
JS_SetContextPrivate(ctx, interpreter);
|
||||||
//JS_SetOptions(ctx, JSOPTION_VAROBJFIX | JS_METHODJIT);
|
//JS_SetOptions(ctx, JSOPTION_VAROBJFIX | JS_METHODJIT);
|
||||||
JS_SetErrorReporter(ctx, error_reporter);
|
JS_SetErrorReporter(spidermonkey_runtime, error_reporter);
|
||||||
JS_SetInterruptCallback(spidermonkey_runtime, heartbeat_callback);
|
JS_SetInterruptCallback(spidermonkey_runtime, heartbeat_callback);
|
||||||
JS::RootedObject window_obj(ctx, JS_NewGlobalObject(ctx, &window_class, NULL, JS::DontFireOnNewGlobalHook));
|
JS::RootedObject window_obj(ctx, JS_NewGlobalObject(ctx, &window_class, NULL, JS::DontFireOnNewGlobalHook));
|
||||||
|
|
||||||
@ -265,8 +265,9 @@ spidermonkey_eval(struct ecmascript_interpreter *interpreter,
|
|||||||
|
|
||||||
JS::RootedObject cg(ctx, JS::CurrentGlobalOrNull(ctx));
|
JS::RootedObject cg(ctx, JS::CurrentGlobalOrNull(ctx));
|
||||||
JS::RootedValue r_val(ctx, rval);
|
JS::RootedValue r_val(ctx, rval);
|
||||||
|
JS::CompileOptions options(ctx);
|
||||||
|
|
||||||
JS_EvaluateScript(ctx, cg, code->source, code->length, "", 0, &r_val);
|
JS::Evaluate(ctx, cg, options, code->source, code->length, &r_val);
|
||||||
done_heartbeat(interpreter->heartbeat);
|
done_heartbeat(interpreter->heartbeat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,7 +288,14 @@ spidermonkey_eval_stringback(struct ecmascript_interpreter *interpreter,
|
|||||||
|
|
||||||
JS::RootedObject cg(ctx, JS::CurrentGlobalOrNull(ctx));
|
JS::RootedObject cg(ctx, JS::CurrentGlobalOrNull(ctx));
|
||||||
JS::RootedValue r_rval(ctx, rval);
|
JS::RootedValue r_rval(ctx, rval);
|
||||||
ret = JS_EvaluateScript(ctx, cg, code->source, code->length, "", 0, &r_rval);
|
JS::CompileOptions options(ctx);
|
||||||
|
|
||||||
|
// options.setIntroductionType("js shell load")
|
||||||
|
// .setUTF8(true)
|
||||||
|
// .setCompileAndGo(true)
|
||||||
|
// .setNoScriptRval(true);
|
||||||
|
|
||||||
|
ret = JS::Evaluate(ctx, cg, options, code->source, code->length, &r_rval);
|
||||||
done_heartbeat(interpreter->heartbeat);
|
done_heartbeat(interpreter->heartbeat);
|
||||||
|
|
||||||
if (ret == false) {
|
if (ret == false) {
|
||||||
@ -298,7 +306,7 @@ spidermonkey_eval_stringback(struct ecmascript_interpreter *interpreter,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return stracpy(JS_EncodeString(ctx, JS::ToString(ctx, r_rval)));
|
return stracpy(JS_EncodeString(ctx, r_rval.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -307,7 +315,7 @@ spidermonkey_eval_boolback(struct ecmascript_interpreter *interpreter,
|
|||||||
struct string *code)
|
struct string *code)
|
||||||
{
|
{
|
||||||
JSContext *ctx;
|
JSContext *ctx;
|
||||||
JSFunction *fun;
|
JS::RootedFunction fun(ctx);
|
||||||
jsval rval;
|
jsval rval;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -317,16 +325,16 @@ spidermonkey_eval_boolback(struct ecmascript_interpreter *interpreter,
|
|||||||
interpreter->ret = NULL;
|
interpreter->ret = NULL;
|
||||||
|
|
||||||
JS::CompileOptions options(ctx);
|
JS::CompileOptions options(ctx);
|
||||||
JS::RootedObject cg(ctx, JS::CurrentGlobalOrNull(ctx));
|
JS::AutoObjectVector ag(ctx);
|
||||||
fun = JS_CompileFunction(ctx, cg, "", 0, NULL, code->source,
|
if (!JS::CompileFunction(ctx, ag, options, "", 0, nullptr, code->source,
|
||||||
code->length, options);
|
code->length, &fun)) {
|
||||||
if (!fun)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
};
|
||||||
|
|
||||||
interpreter->heartbeat = add_heartbeat(interpreter);
|
interpreter->heartbeat = add_heartbeat(interpreter);
|
||||||
JS::RootedFunction r_fun(ctx, fun);
|
|
||||||
JS::RootedValue r_val(ctx, rval);
|
JS::RootedValue r_val(ctx, rval);
|
||||||
ret = JS_CallFunction(ctx, cg, r_fun, JS::HandleValueArray::empty(), &r_val);
|
JS::RootedObject cg(ctx, JS::CurrentGlobalOrNull(ctx));
|
||||||
|
ret = JS_CallFunction(ctx, cg, fun, JS::HandleValueArray::empty(), &r_val);
|
||||||
done_heartbeat(interpreter->heartbeat);
|
done_heartbeat(interpreter->heartbeat);
|
||||||
|
|
||||||
if (ret == 2) { /* onClick="history.back()" */
|
if (ret == 2) { /* onClick="history.back()" */
|
||||||
@ -335,12 +343,12 @@ spidermonkey_eval_boolback(struct ecmascript_interpreter *interpreter,
|
|||||||
if (ret == false) {
|
if (ret == false) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (JSVAL_IS_VOID(rval)) {
|
if (r_val.isUndefined()) {
|
||||||
/* Undefined value. */
|
/* Undefined value. */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return jsval_to_boolean(ctx, &rval);
|
return r_val.toBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct module spidermonkey_module = struct_module(
|
struct module spidermonkey_module = struct_module(
|
||||||
|
@ -53,9 +53,9 @@ static bool document_get_property(JSContext *ctx, JS::HandleObject hobj, JS::Han
|
|||||||
JSClass document_class = {
|
JSClass document_class = {
|
||||||
"document",
|
"document",
|
||||||
JSCLASS_HAS_PRIVATE,
|
JSCLASS_HAS_PRIVATE,
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
document_get_property, JS_StrictPropertyStub,
|
document_get_property, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub
|
nullptr, nullptr, nullptr
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef CONFIG_COOKIES
|
#ifdef CONFIG_COOKIES
|
||||||
|
@ -69,9 +69,9 @@ static void form_finalize(JSFreeOp *op, JSObject *obj);
|
|||||||
static JSClass form_class = {
|
static JSClass form_class = {
|
||||||
"form",
|
"form",
|
||||||
JSCLASS_HAS_PRIVATE, /* struct form_view *, or NULL if detached */
|
JSCLASS_HAS_PRIVATE, /* struct form_view *, or NULL if detached */
|
||||||
JS_PropertyStub, JS_PropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
form_get_property, JS_StrictPropertyStub,
|
form_get_property, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, form_finalize
|
nullptr, nullptr, nullptr, form_finalize
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -89,9 +89,9 @@ static void input_finalize(JSFreeOp *op, JSObject *obj);
|
|||||||
static JSClass input_class = {
|
static JSClass input_class = {
|
||||||
"input", /* here, we unleash ourselves */
|
"input", /* here, we unleash ourselves */
|
||||||
JSCLASS_HAS_PRIVATE, /* struct form_state *, or NULL if detached */
|
JSCLASS_HAS_PRIVATE, /* struct form_state *, or NULL if detached */
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
input_get_property, input_set_property,
|
input_get_property, input_set_property,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, input_finalize
|
nullptr, nullptr, nullptr, input_finalize
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Tinyids of properties. Use negative values to distinguish these
|
/* Tinyids of properties. Use negative values to distinguish these
|
||||||
@ -228,12 +228,43 @@ input_set_property_accessKey(JSContext *ctx, unsigned int argc, jsval *vp)
|
|||||||
/* Hiddens have no link. */
|
/* Hiddens have no link. */
|
||||||
if (linknum >= 0) link = &document->links[linknum];
|
if (linknum >= 0) link = &document->links[linknum];
|
||||||
|
|
||||||
accesskey = jsval_to_accesskey(ctx, args[0]);
|
// accesskey = jsval_to_accesskey(ctx, args[0]);
|
||||||
|
|
||||||
if (accesskey == UCS_NO_CHAR)
|
size_t len;
|
||||||
|
char16_t chr[2];
|
||||||
|
|
||||||
|
accesskey = UCS_NO_CHAR;
|
||||||
|
|
||||||
|
if (!args[0].isString()) {
|
||||||
return false;
|
return false;
|
||||||
else if (link)
|
}
|
||||||
|
JSString *str = args[0].toString();
|
||||||
|
|
||||||
|
len = JS_GetStringLength(str);
|
||||||
|
|
||||||
|
/* This implementation ignores extra characters in the string. */
|
||||||
|
if (len < 1) {
|
||||||
|
accesskey = 0; /* which means no access key */
|
||||||
|
} else if (len == 1) {
|
||||||
|
JS_GetStringCharAt(ctx, str, 0, &chr[0]);
|
||||||
|
if (!is_utf16_surrogate(chr[0])) {
|
||||||
|
accesskey = chr[0];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
JS_GetStringCharAt(ctx, str, 1, &chr[1]);
|
||||||
|
if (is_utf16_high_surrogate(chr[0])
|
||||||
|
&& is_utf16_low_surrogate(chr[1])) {
|
||||||
|
accesskey = join_utf16_surrogates(chr[0], chr[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (accesskey == UCS_NO_CHAR) {
|
||||||
|
JS_ReportError(ctx, "Invalid UTF-16 sequence");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (link) {
|
||||||
link->accesskey = accesskey;
|
link->accesskey = accesskey;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1601,8 +1632,7 @@ input_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, bool
|
|||||||
: FORM_MODE_NORMAL);
|
: FORM_MODE_NORMAL);
|
||||||
break;
|
break;
|
||||||
case JSP_INPUT_MAX_LENGTH:
|
case JSP_INPUT_MAX_LENGTH:
|
||||||
if (!JS::ToInt32(ctx, hvp, &fc->maxlength))
|
fc->maxlength = hvp.toInt32();
|
||||||
return false;
|
|
||||||
break;
|
break;
|
||||||
case JSP_INPUT_NAME:
|
case JSP_INPUT_NAME:
|
||||||
mem_free_set(&fc->name, stracpy(jsval_to_string(ctx, vp)));
|
mem_free_set(&fc->name, stracpy(jsval_to_string(ctx, vp)));
|
||||||
@ -1627,10 +1657,7 @@ input_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, bool
|
|||||||
break;
|
break;
|
||||||
case JSP_INPUT_SELECTED_INDEX:
|
case JSP_INPUT_SELECTED_INDEX:
|
||||||
if (fc->type == FC_SELECT) {
|
if (fc->type == FC_SELECT) {
|
||||||
int item;
|
int item = hvp.toInt32();
|
||||||
|
|
||||||
if (!JS::ToInt32(ctx, hvp, &item))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (item >= 0 && item < fc->nvalues) {
|
if (item >= 0 && item < fc->nvalues) {
|
||||||
fs->state = item;
|
fs->state = item;
|
||||||
@ -1798,7 +1825,7 @@ get_input_object(JSContext *ctx, JSObject *jsform, struct form_state *fs)
|
|||||||
/* jsform ('form') is input's parent */
|
/* jsform ('form') is input's parent */
|
||||||
/* FIXME: That is NOT correct since the real containing element
|
/* FIXME: That is NOT correct since the real containing element
|
||||||
* should be its parent, but gimme DOM first. --pasky */
|
* should be its parent, but gimme DOM first. --pasky */
|
||||||
jsinput = JS_NewObject(ctx, &input_class, JS::NullPtr(), r_jsform);
|
jsinput = JS_NewObject(ctx, &input_class, r_jsform);
|
||||||
if (!jsinput)
|
if (!jsinput)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -1908,13 +1935,13 @@ static bool form_elements_get_property(JSContext *ctx, JS::HandleObject hobj, JS
|
|||||||
static JSClass form_elements_class = {
|
static JSClass form_elements_class = {
|
||||||
"elements",
|
"elements",
|
||||||
JSCLASS_HAS_PRIVATE,
|
JSCLASS_HAS_PRIVATE,
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
form_elements_get_property, JS_StrictPropertyStub,
|
form_elements_get_property, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL
|
nullptr, nullptr, nullptr, nullptr
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool form_elements_item2(JSContext *ctx, JSObject *obj, int index, jsval *rval);
|
static bool form_elements_item2(JSContext *ctx, JS::HandleObject hobj, int index, JS::MutableHandleValue hvp);
|
||||||
static bool form_elements_namedItem2(JSContext *ctx, JSObject *obj, unsigned char *string, jsval *rval);
|
static bool form_elements_namedItem2(JSContext *ctx, JS::HandleObject hobj, unsigned char *string, JS::MutableHandleValue hvp);
|
||||||
static bool form_elements_item(JSContext *ctx, unsigned int argc, jsval *rval);
|
static bool form_elements_item(JSContext *ctx, unsigned int argc, jsval *rval);
|
||||||
static bool form_elements_namedItem(JSContext *ctx, unsigned int argc, jsval *rval);
|
static bool form_elements_namedItem(JSContext *ctx, unsigned int argc, jsval *rval);
|
||||||
|
|
||||||
@ -1942,7 +1969,6 @@ static JSPropertySpec form_elements_props[] = {
|
|||||||
static bool
|
static bool
|
||||||
form_elements_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
form_elements_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
|
||||||
jsid id = hid.get();
|
jsid id = hid.get();
|
||||||
|
|
||||||
jsval idval;
|
jsval idval;
|
||||||
@ -1962,7 +1988,7 @@ form_elements_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h
|
|||||||
if (!JS_InstanceOf(ctx, hobj, &form_elements_class, NULL)) {
|
if (!JS_InstanceOf(ctx, hobj, &form_elements_class, NULL)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
parent_form = JS_GetParent(obj);
|
parent_form = JS_GetParent(hobj);
|
||||||
assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL));
|
assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL));
|
||||||
if_assert_failed return false;
|
if_assert_failed return false;
|
||||||
parent_doc = JS_GetParent(parent_form);
|
parent_doc = JS_GetParent(parent_form);
|
||||||
@ -1983,8 +2009,8 @@ form_elements_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h
|
|||||||
if (JSID_IS_STRING(id)) {
|
if (JSID_IS_STRING(id)) {
|
||||||
JS::RootedValue r_idval(ctx, idval);
|
JS::RootedValue r_idval(ctx, idval);
|
||||||
JS_IdToValue(ctx, id, &r_idval);
|
JS_IdToValue(ctx, id, &r_idval);
|
||||||
unsigned char *string = JS_EncodeString(ctx, JS::ToString(ctx, r_idval));
|
unsigned char *string = JS_EncodeString(ctx, r_idval.toString());
|
||||||
form_elements_namedItem2(ctx, obj, string, vp);
|
form_elements_namedItem2(ctx, hobj, string, hvp);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1992,19 +2018,19 @@ form_elements_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
undef_to_jsval(ctx, vp);
|
hvp.setUndefined();
|
||||||
|
|
||||||
switch (JSID_TO_INT(id)) {
|
switch (JSID_TO_INT(id)) {
|
||||||
case JSP_FORM_ELEMENTS_LENGTH:
|
case JSP_FORM_ELEMENTS_LENGTH:
|
||||||
int_to_jsval(ctx, vp, list_size(&form->items));
|
hvp.setInt32(list_size(&form->items));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* Array index. */
|
/* Array index. */
|
||||||
int index;
|
int index;
|
||||||
JS::RootedValue r_idval(ctx, idval);
|
JS::RootedValue r_idval(ctx, idval);
|
||||||
JS_IdToValue(ctx, id, &r_idval);
|
JS_IdToValue(ctx, id, &r_idval);
|
||||||
JS::ToInt32(ctx, r_idval, &index);
|
index = r_idval.toInt32();
|
||||||
form_elements_item2(ctx, obj, index, vp);
|
form_elements_item2(ctx, hobj, index, hvp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2056,24 +2082,23 @@ form_elements_get_property_length(JSContext *ctx, unsigned int argc, jsval *vp)
|
|||||||
|
|
||||||
/* @form_elements_funcs{"item"} */
|
/* @form_elements_funcs{"item"} */
|
||||||
static bool
|
static bool
|
||||||
form_elements_item(JSContext *ctx, unsigned int argc, jsval *rval)
|
form_elements_item(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
jsval val = JSVAL_VOID;
|
jsval val = JSVAL_VOID;
|
||||||
JSObject *obj = JS_THIS_OBJECT(ctx, rval);
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
JS::RootedValue rval(ctx, val);
|
||||||
|
|
||||||
int index;
|
int index = args[0].toInt32();
|
||||||
JS::ToInt32(ctx, args[0], &index);
|
|
||||||
|
|
||||||
bool ret = form_elements_item2(ctx, obj, index, &val);
|
bool ret = form_elements_item2(ctx, hobj, index, &rval);
|
||||||
|
args.rval().set(rval.get());
|
||||||
|
|
||||||
args.rval().set(val);
|
|
||||||
// JS_SET_RVAL(ctx, rval, val);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
form_elements_item2(JSContext *ctx, JSObject *obj, int index, jsval *rval)
|
form_elements_item2(JSContext *ctx, JS::HandleObject hobj, int index, JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
JS::RootedObject parent_form(ctx); /* instance of @form_class */
|
JS::RootedObject parent_form(ctx); /* instance of @form_class */
|
||||||
JS::RootedObject parent_doc(ctx); /* instance of @document_class */
|
JS::RootedObject parent_doc(ctx); /* instance of @document_class */
|
||||||
@ -2086,10 +2111,8 @@ form_elements_item2(JSContext *ctx, JSObject *obj, int index, jsval *rval)
|
|||||||
struct el_form_control *fc;
|
struct el_form_control *fc;
|
||||||
int counter = -1;
|
int counter = -1;
|
||||||
|
|
||||||
JS::RootedObject hobj(ctx, obj);
|
|
||||||
|
|
||||||
if (!JS_InstanceOf(ctx, hobj, &form_elements_class, NULL)) return false;
|
if (!JS_InstanceOf(ctx, hobj, &form_elements_class, NULL)) return false;
|
||||||
parent_form = JS_GetParent(obj);
|
parent_form = JS_GetParent(hobj);
|
||||||
assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL));
|
assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL));
|
||||||
if_assert_failed return false;
|
if_assert_failed return false;
|
||||||
parent_doc = JS_GetParent(parent_form);
|
parent_doc = JS_GetParent(parent_form);
|
||||||
@ -2107,7 +2130,7 @@ form_elements_item2(JSContext *ctx, JSObject *obj, int index, jsval *rval)
|
|||||||
if (!form_view) return false; /* detached */
|
if (!form_view) return false; /* detached */
|
||||||
form = find_form_by_form_view(document, form_view);
|
form = find_form_by_form_view(document, form_view);
|
||||||
|
|
||||||
undef_to_jsval(ctx, rval);
|
hvp.setUndefined();
|
||||||
|
|
||||||
foreach (fc, form->items) {
|
foreach (fc, form->items) {
|
||||||
counter++;
|
counter++;
|
||||||
@ -2117,8 +2140,9 @@ form_elements_item2(JSContext *ctx, JSObject *obj, int index, jsval *rval)
|
|||||||
if (fs) {
|
if (fs) {
|
||||||
JSObject *fcobj = get_form_control_object(ctx, parent_form, fc->type, fs);
|
JSObject *fcobj = get_form_control_object(ctx, parent_form, fc->type, fs);
|
||||||
|
|
||||||
if (fcobj)
|
if (fcobj) {
|
||||||
object_to_jsval(ctx, rval, fcobj);
|
hvp.setObject(*fcobj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -2129,21 +2153,24 @@ form_elements_item2(JSContext *ctx, JSObject *obj, int index, jsval *rval)
|
|||||||
|
|
||||||
/* @form_elements_funcs{"namedItem"} */
|
/* @form_elements_funcs{"namedItem"} */
|
||||||
static bool
|
static bool
|
||||||
form_elements_namedItem(JSContext *ctx, unsigned int argc, jsval *rval)
|
form_elements_namedItem(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
jsval val = JSVAL_VOID;
|
jsval val = JSVAL_VOID;
|
||||||
JSObject *obj = JS_THIS_OBJECT(ctx, rval);
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
JS::RootedValue rval(ctx, val);
|
||||||
|
|
||||||
|
|
||||||
// jsval *argv = JS_ARGV(ctx, rval);
|
// jsval *argv = JS_ARGV(ctx, rval);
|
||||||
unsigned char *string = JS_EncodeString(ctx, JS::ToString(ctx, args[0]));
|
unsigned char *string = JS_EncodeString(ctx, args[0].toString());
|
||||||
bool ret = form_elements_namedItem2(ctx, obj, string, &val);
|
bool ret = form_elements_namedItem2(ctx, hobj, string, &rval);
|
||||||
args.rval().set(val);
|
args.rval().set(rval);
|
||||||
// JS_SET_RVAL(ctx, rval, val);
|
// JS_SET_RVAL(ctx, rval, val);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
form_elements_namedItem2(JSContext *ctx, JSObject *obj, unsigned char *string, jsval *rval)
|
form_elements_namedItem2(JSContext *ctx, JS::HandleObject hobj, unsigned char *string, JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
JS::RootedObject parent_form(ctx); /* instance of @form_class */
|
JS::RootedObject parent_form(ctx); /* instance of @form_class */
|
||||||
JS::RootedObject parent_doc(ctx); /* instance of @document_class */
|
JS::RootedObject parent_doc(ctx); /* instance of @document_class */
|
||||||
@ -2159,10 +2186,8 @@ form_elements_namedItem2(JSContext *ctx, JSObject *obj, unsigned char *string, j
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::RootedObject hobj(ctx, obj);
|
|
||||||
|
|
||||||
if (!JS_InstanceOf(ctx, hobj, &form_elements_class, NULL)) return false;
|
if (!JS_InstanceOf(ctx, hobj, &form_elements_class, NULL)) return false;
|
||||||
parent_form = JS_GetParent(obj);
|
parent_form = JS_GetParent(hobj);
|
||||||
assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL));
|
assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL));
|
||||||
if_assert_failed return false;
|
if_assert_failed return false;
|
||||||
parent_doc = JS_GetParent(parent_form);
|
parent_doc = JS_GetParent(parent_form);
|
||||||
@ -2180,7 +2205,7 @@ form_elements_namedItem2(JSContext *ctx, JSObject *obj, unsigned char *string, j
|
|||||||
if (!form_view) return false; /* detached */
|
if (!form_view) return false; /* detached */
|
||||||
form = find_form_by_form_view(document, form_view);
|
form = find_form_by_form_view(document, form_view);
|
||||||
|
|
||||||
undef_to_jsval(ctx, rval);
|
hvp.setUndefined();
|
||||||
|
|
||||||
foreach (fc, form->items) {
|
foreach (fc, form->items) {
|
||||||
if ((fc->id && !c_strcasecmp(string, fc->id))
|
if ((fc->id && !c_strcasecmp(string, fc->id))
|
||||||
@ -2190,8 +2215,9 @@ form_elements_namedItem2(JSContext *ctx, JSObject *obj, unsigned char *string, j
|
|||||||
if (fs) {
|
if (fs) {
|
||||||
JSObject *fcobj = get_form_control_object(ctx, parent_form, fc->type, fs);
|
JSObject *fcobj = get_form_control_object(ctx, parent_form, fc->type, fs);
|
||||||
|
|
||||||
if (fcobj)
|
if (fcobj) {
|
||||||
object_to_jsval(ctx, rval, fcobj);
|
hvp.setObject(*fcobj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -2325,7 +2351,7 @@ form_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::M
|
|||||||
case JSP_FORM_ELEMENTS:
|
case JSP_FORM_ELEMENTS:
|
||||||
{
|
{
|
||||||
/* jsform ('form') is form_elements' parent; who knows is that's correct */
|
/* jsform ('form') is form_elements' parent; who knows is that's correct */
|
||||||
JSObject *jsform_elems = JS_NewObject(ctx, &form_elements_class, JS::NullPtr(), hobj);
|
JSObject *jsform_elems = JS_NewObject(ctx, &form_elements_class, hobj);
|
||||||
|
|
||||||
JS::RootedObject r_jsform_elems(ctx, jsform_elems);
|
JS::RootedObject r_jsform_elems(ctx, jsform_elems);
|
||||||
|
|
||||||
@ -2500,7 +2526,7 @@ form_get_property_elements(JSContext *ctx, unsigned int argc, jsval *vp)
|
|||||||
if (!fv) return false; /* detached */
|
if (!fv) return false; /* detached */
|
||||||
|
|
||||||
/* jsform ('form') is form_elements' parent; who knows is that's correct */
|
/* jsform ('form') is form_elements' parent; who knows is that's correct */
|
||||||
JSObject *jsform_elems = JS_NewObject(ctx, &form_elements_class, JS::NullPtr(), hobj);
|
JSObject *jsform_elems = JS_NewObject(ctx, &form_elements_class, hobj);
|
||||||
JS::RootedObject r_jsform_elems(ctx, jsform_elems);
|
JS::RootedObject r_jsform_elems(ctx, jsform_elems);
|
||||||
|
|
||||||
JS_DefineProperties(ctx, r_jsform_elems, (JSPropertySpec *) form_elements_props);
|
JS_DefineProperties(ctx, r_jsform_elems, (JSPropertySpec *) form_elements_props);
|
||||||
@ -3030,7 +3056,7 @@ get_form_object(JSContext *ctx, JSObject *jsdoc, struct form_view *fv)
|
|||||||
/* jsdoc ('document') is fv's parent */
|
/* jsdoc ('document') is fv's parent */
|
||||||
/* FIXME: That is NOT correct since the real containing element
|
/* FIXME: That is NOT correct since the real containing element
|
||||||
* should be its parent, but gimme DOM first. --pasky */
|
* should be its parent, but gimme DOM first. --pasky */
|
||||||
jsform = JS_NewObject(ctx, &form_class, JS::NullPtr(), r_jsdoc);
|
jsform = JS_NewObject(ctx, &form_class, r_jsdoc);
|
||||||
if (jsform == NULL)
|
if (jsform == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
JS::RootedObject r_jsform(ctx, jsform);
|
JS::RootedObject r_jsform(ctx, jsform);
|
||||||
@ -3095,13 +3121,13 @@ static bool forms_get_property_length(JSContext *ctx, unsigned int argc, jsval *
|
|||||||
JSClass forms_class = {
|
JSClass forms_class = {
|
||||||
"forms",
|
"forms",
|
||||||
JSCLASS_HAS_PRIVATE,
|
JSCLASS_HAS_PRIVATE,
|
||||||
JS_PropertyStub, JS_PropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
forms_get_property, JS_StrictPropertyStub,
|
forms_get_property, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL
|
nullptr, nullptr, nullptr, nullptr
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool forms_item(JSContext *ctx, unsigned int argc, jsval *rval);
|
static bool forms_item(JSContext *ctx, unsigned int argc, jsval *rval);
|
||||||
static bool forms_item2(JSContext *ctx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
|
static bool forms_item2(JSContext *ctx, JS::HandleObject hobj, int index, JS::MutableHandleValue hvp);
|
||||||
static bool forms_namedItem(JSContext *ctx, unsigned int argc, jsval *rval);
|
static bool forms_namedItem(JSContext *ctx, unsigned int argc, jsval *rval);
|
||||||
|
|
||||||
const spidermonkeyFunctionSpec forms_funcs[] = {
|
const spidermonkeyFunctionSpec forms_funcs[] = {
|
||||||
@ -3126,9 +3152,9 @@ JSPropertySpec forms_props[] = {
|
|||||||
* string (but might not be). If found, set *rval = the DOM
|
* string (but might not be). If found, set *rval = the DOM
|
||||||
* object. If not found, leave *rval unchanged. */
|
* object. If not found, leave *rval unchanged. */
|
||||||
static void
|
static void
|
||||||
find_form_by_name(JSContext *ctx, JSObject *jsdoc,
|
find_form_by_name(JSContext *ctx, JS::HandleObject jsdoc,
|
||||||
struct document_view *doc_view,
|
struct document_view *doc_view,
|
||||||
unsigned char *string, jsval *rval)
|
unsigned char *string, JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
struct form *form;
|
struct form *form;
|
||||||
|
|
||||||
@ -3137,7 +3163,7 @@ find_form_by_name(JSContext *ctx, JSObject *jsdoc,
|
|||||||
|
|
||||||
foreach (form, doc_view->document->forms) {
|
foreach (form, doc_view->document->forms) {
|
||||||
if (form->name && !c_strcasecmp(string, form->name)) {
|
if (form->name && !c_strcasecmp(string, form->name)) {
|
||||||
object_to_jsval(ctx, rval, get_form_object(ctx, jsdoc,
|
hvp.setObject(*get_form_object(ctx, jsdoc,
|
||||||
find_form_view(doc_view, form)));
|
find_form_view(doc_view, form)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -3148,7 +3174,6 @@ find_form_by_name(JSContext *ctx, JSObject *jsdoc,
|
|||||||
static bool
|
static bool
|
||||||
forms_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
forms_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
ELINKS_CAST_PROP_PARAMS
|
|
||||||
jsid id = hid.get();
|
jsid id = hid.get();
|
||||||
|
|
||||||
jsval idval;
|
jsval idval;
|
||||||
@ -3163,7 +3188,7 @@ forms_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::
|
|||||||
if (!JS_InstanceOf(ctx, hobj, &forms_class, NULL))
|
if (!JS_InstanceOf(ctx, hobj, &forms_class, NULL))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
parent_doc = JS_GetParent(obj);
|
parent_doc = JS_GetParent(hobj);
|
||||||
assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL));
|
assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL));
|
||||||
if_assert_failed return false;
|
if_assert_failed return false;
|
||||||
|
|
||||||
@ -3190,8 +3215,8 @@ forms_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::
|
|||||||
* we must leave *vp unchanged here, to avoid
|
* we must leave *vp unchanged here, to avoid
|
||||||
* "TypeError: forms.namedItem is not a function". */
|
* "TypeError: forms.namedItem is not a function". */
|
||||||
JS_IdToValue(ctx, id, &r_idval);
|
JS_IdToValue(ctx, id, &r_idval);
|
||||||
unsigned char *string = JS_EncodeString(ctx, JS::ToString(ctx, r_idval));
|
unsigned char *string = JS_EncodeString(ctx, r_idval.toString());
|
||||||
find_form_by_name(ctx, parent_doc, doc_view, string, vp);
|
find_form_by_name(ctx, parent_doc, doc_view, string, hvp);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -3199,7 +3224,8 @@ forms_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::
|
|||||||
/* Array index. */
|
/* Array index. */
|
||||||
JS::RootedValue r_idval(ctx, idval);
|
JS::RootedValue r_idval(ctx, idval);
|
||||||
JS_IdToValue(ctx, id, &r_idval);
|
JS_IdToValue(ctx, id, &r_idval);
|
||||||
forms_item2(ctx, obj, 1, &idval, vp);
|
int index = r_idval.toInt32();
|
||||||
|
forms_item2(ctx, hobj, index, hvp);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -3242,36 +3268,36 @@ forms_get_property_length(JSContext *ctx, unsigned int argc, jsval *vp)
|
|||||||
|
|
||||||
/* @forms_funcs{"item"} */
|
/* @forms_funcs{"item"} */
|
||||||
static bool
|
static bool
|
||||||
forms_item(JSContext *ctx, unsigned int argc, jsval *rval)
|
forms_item(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
jsval val = JSVAL_VOID;
|
jsval val = JSVAL_VOID;
|
||||||
JSObject *obj = JS_THIS_OBJECT(ctx, rval);
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
// jsval *argv = JS_ARGV(ctx, rval);
|
JS::RootedValue rval(ctx, val);
|
||||||
bool ret = forms_item2(ctx, obj, argc, rval, &val);
|
|
||||||
|
|
||||||
args.rval().set(val);
|
|
||||||
|
// jsval *argv = JS_ARGV(ctx, rval);
|
||||||
|
int index = args[0].toInt32();
|
||||||
|
bool ret = forms_item2(ctx, hobj, index, &rval);
|
||||||
|
|
||||||
|
args.rval().set(rval.get());
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
forms_item2(JSContext *ctx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval)
|
forms_item2(JSContext *ctx, JS::HandleObject hobj, int index, JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
JS::RootedObject parent_doc(ctx); /* instance of @document_class */
|
JS::RootedObject parent_doc(ctx); /* instance of @document_class */
|
||||||
JS::RootedObject parent_win(ctx); /* instance of @window_class */
|
JS::RootedObject parent_win(ctx); /* instance of @window_class */
|
||||||
struct view_state *vs;
|
struct view_state *vs;
|
||||||
struct form_view *fv;
|
struct form_view *fv;
|
||||||
int counter = -1;
|
int counter = -1;
|
||||||
int index;
|
|
||||||
|
|
||||||
JS::RootedObject hobj(ctx, obj);
|
if (!JS_InstanceOf(ctx, hobj, &forms_class, NULL))
|
||||||
JS::CallArgs args = JS::CallArgsFromVp(argc, argv);
|
|
||||||
|
|
||||||
if (!JS_InstanceOf(ctx, hobj, &forms_class, &args))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
parent_doc = JS_GetParent(obj);
|
parent_doc = JS_GetParent(hobj);
|
||||||
assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL));
|
assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL));
|
||||||
if_assert_failed return false;
|
if_assert_failed return false;
|
||||||
|
|
||||||
@ -3282,18 +3308,12 @@ forms_item2(JSContext *ctx, JSObject *obj, unsigned int argc, jsval *argv, jsval
|
|||||||
vs = JS_GetInstancePrivate(ctx, parent_win,
|
vs = JS_GetInstancePrivate(ctx, parent_win,
|
||||||
&window_class, NULL);
|
&window_class, NULL);
|
||||||
|
|
||||||
if (argc != 1)
|
hvp.setUndefined();
|
||||||
return true;
|
|
||||||
|
|
||||||
if (!JS::ToInt32(ctx, args[0], &index))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
undef_to_jsval(ctx, rval);
|
|
||||||
|
|
||||||
foreach (fv, vs->forms) {
|
foreach (fv, vs->forms) {
|
||||||
counter++;
|
counter++;
|
||||||
if (counter == index) {
|
if (counter == index) {
|
||||||
object_to_jsval(ctx, rval, get_form_object(ctx, parent_doc, fv));
|
hvp.setObject(*get_form_object(ctx, parent_doc, fv));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3303,21 +3323,20 @@ forms_item2(JSContext *ctx, JSObject *obj, unsigned int argc, jsval *argv, jsval
|
|||||||
|
|
||||||
/* @forms_funcs{"namedItem"} */
|
/* @forms_funcs{"namedItem"} */
|
||||||
static bool
|
static bool
|
||||||
forms_namedItem(JSContext *ctx, unsigned int argc, jsval *rval)
|
forms_namedItem(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
{
|
{
|
||||||
jsval val;
|
jsval val;
|
||||||
JS::RootedObject parent_doc(ctx); /* instance of @document_class */
|
JS::RootedObject parent_doc(ctx); /* instance of @document_class */
|
||||||
JS::RootedObject parent_win(ctx); /* instance of @window_class */
|
JS::RootedObject parent_win(ctx); /* instance of @window_class */
|
||||||
JSObject *obj = JS_THIS_OBJECT(ctx, rval);
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
// jsval *argv = JS_ARGV(ctx, rval);
|
// jsval *argv = JS_ARGV(ctx, rval);
|
||||||
struct view_state *vs;
|
struct view_state *vs;
|
||||||
struct document_view *doc_view;
|
struct document_view *doc_view;
|
||||||
|
|
||||||
JS::RootedObject hobj(ctx, obj);
|
|
||||||
|
|
||||||
if (!JS_InstanceOf(ctx, hobj, &forms_class, &args)) return false;
|
if (!JS_InstanceOf(ctx, hobj, &forms_class, &args)) return false;
|
||||||
parent_doc = JS_GetParent(obj);
|
parent_doc = JS_GetParent(hobj);
|
||||||
assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL));
|
assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL));
|
||||||
if_assert_failed return false;
|
if_assert_failed return false;
|
||||||
parent_win = JS_GetParent(parent_doc);
|
parent_win = JS_GetParent(parent_doc);
|
||||||
@ -3331,11 +3350,13 @@ forms_namedItem(JSContext *ctx, unsigned int argc, jsval *rval)
|
|||||||
if (argc != 1)
|
if (argc != 1)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
undef_to_jsval(ctx, &val);
|
args.rval().setUndefined();
|
||||||
unsigned char *string = JS_EncodeString(ctx, args[0].toString());
|
unsigned char *string = JS_EncodeString(ctx, args[0].toString());
|
||||||
|
|
||||||
find_form_by_name(ctx, parent_doc, doc_view, string, &val);
|
JS::RootedValue rval(ctx, val);
|
||||||
args.rval().set(val);
|
|
||||||
|
find_form_by_name(ctx, parent_doc, doc_view, string, &rval);
|
||||||
|
args.rval().set(rval.get());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -3344,7 +3365,7 @@ forms_namedItem(JSContext *ctx, unsigned int argc, jsval *rval)
|
|||||||
static JSString *
|
static JSString *
|
||||||
unicode_to_jsstring(JSContext *ctx, unicode_val_T u)
|
unicode_to_jsstring(JSContext *ctx, unicode_val_T u)
|
||||||
{
|
{
|
||||||
jschar buf[2];
|
char16_t buf[2];
|
||||||
|
|
||||||
/* This is supposed to make a string from which
|
/* This is supposed to make a string from which
|
||||||
* jsval_to_accesskey() can get the original @u back.
|
* jsval_to_accesskey() can get the original @u back.
|
||||||
@ -3373,23 +3394,25 @@ static unicode_val_T
|
|||||||
jsval_to_accesskey(JSContext *ctx, JS::MutableHandleValue hvp)
|
jsval_to_accesskey(JSContext *ctx, JS::MutableHandleValue hvp)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
const jschar *chr;
|
char16_t chr[2];
|
||||||
|
|
||||||
JSString *str = JS::ToString(ctx, hvp);
|
JSString *str = hvp.toString();
|
||||||
|
|
||||||
len = JS_GetStringLength(str);
|
len = JS_GetStringLength(str);
|
||||||
chr = JS_GetStringCharsZ(ctx, str);
|
|
||||||
|
|
||||||
/* This implementation ignores extra characters in the string. */
|
/* This implementation ignores extra characters in the string. */
|
||||||
if (len < 1)
|
if (len < 1)
|
||||||
return 0; /* which means no access key */
|
return 0; /* which means no access key */
|
||||||
|
JS_GetStringCharAt(ctx, str, 0, &chr[0]);
|
||||||
if (!is_utf16_surrogate(chr[0])) {
|
if (!is_utf16_surrogate(chr[0])) {
|
||||||
return chr[0];
|
return chr[0];
|
||||||
}
|
}
|
||||||
if (len >= 2
|
if (len >= 2) {
|
||||||
&& is_utf16_high_surrogate(chr[0])
|
JS_GetStringCharAt(ctx, str, 1, &chr[1]);
|
||||||
&& is_utf16_low_surrogate(chr[1])) {
|
if (is_utf16_high_surrogate(chr[0])
|
||||||
return join_utf16_surrogates(chr[0], chr[1]);
|
&& is_utf16_low_surrogate(chr[1])) {
|
||||||
|
return join_utf16_surrogates(chr[0], chr[1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
JS_ReportError(ctx, "Invalid UTF-16 sequence");
|
JS_ReportError(ctx, "Invalid UTF-16 sequence");
|
||||||
return UCS_NO_CHAR; /* which the caller will reject */
|
return UCS_NO_CHAR; /* which the caller will reject */
|
||||||
|
@ -52,9 +52,9 @@ static bool history_go(JSContext *ctx, unsigned int argc, jsval *rval);
|
|||||||
JSClass history_class = {
|
JSClass history_class = {
|
||||||
"history",
|
"history",
|
||||||
JSCLASS_HAS_PRIVATE,
|
JSCLASS_HAS_PRIVATE,
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
JS_PropertyStub, JS_StrictPropertyStub,
|
JS_PropertyStub, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL
|
nullptr, nullptr, nullptr, nullptr
|
||||||
};
|
};
|
||||||
|
|
||||||
const spidermonkeyFunctionSpec history_funcs[] = {
|
const spidermonkeyFunctionSpec history_funcs[] = {
|
||||||
@ -107,14 +107,12 @@ history_go(JSContext *ctx, unsigned int argc, jsval *rval)
|
|||||||
struct session *ses = doc_view->session;
|
struct session *ses = doc_view->session;
|
||||||
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
JS::CallArgs args = JS::CallArgsFromVp(argc, rval);
|
||||||
|
|
||||||
// jsval *argv = JS_ARGV(ctx, rval);
|
|
||||||
int index;
|
|
||||||
struct location *loc;
|
struct location *loc;
|
||||||
|
|
||||||
if (argc != 1)
|
if (argc != 1)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
index = atol(jsval_to_string(ctx, args[0].address()));
|
int index = args[0].toInt32();
|
||||||
|
|
||||||
for (loc = cur_loc(ses);
|
for (loc = cur_loc(ses);
|
||||||
loc != (struct location *) &ses->history.history;
|
loc != (struct location *) &ses->history.history;
|
||||||
@ -139,9 +137,9 @@ static bool location_set_property_href(JSContext *ctx, unsigned int argc, jsval
|
|||||||
JSClass location_class = {
|
JSClass location_class = {
|
||||||
"location",
|
"location",
|
||||||
JSCLASS_HAS_PRIVATE,
|
JSCLASS_HAS_PRIVATE,
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
JS_PropertyStub, JS_StrictPropertyStub,
|
JS_PropertyStub, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL
|
nullptr, nullptr, nullptr, nullptr
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Tinyids of properties. Use negative values to distinguish these
|
/* Tinyids of properties. Use negative values to distinguish these
|
||||||
|
@ -54,9 +54,9 @@ static bool navigator_get_property_userAgent(JSContext *ctx, unsigned int argc,
|
|||||||
JSClass navigator_class = {
|
JSClass navigator_class = {
|
||||||
"navigator",
|
"navigator",
|
||||||
JSCLASS_HAS_PRIVATE,
|
JSCLASS_HAS_PRIVATE,
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
JS_PropertyStub, JS_StrictPropertyStub,
|
JS_PropertyStub, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL
|
nullptr, nullptr, nullptr, nullptr
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Tinyids of properties. Use negative values to distinguish these
|
/* Tinyids of properties. Use negative values to distinguish these
|
||||||
|
@ -51,17 +51,17 @@ static bool unibar_set_property_visible(JSContext *ctx, unsigned int argc, jsval
|
|||||||
JSClass menubar_class = {
|
JSClass menubar_class = {
|
||||||
"menubar",
|
"menubar",
|
||||||
JSCLASS_HAS_PRIVATE, /* const char * "t" */
|
JSCLASS_HAS_PRIVATE, /* const char * "t" */
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
JS_PropertyStub, JS_StrictPropertyStub,
|
JS_PropertyStub, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL
|
nullptr, nullptr, nullptr, nullptr
|
||||||
};
|
};
|
||||||
/* Each @statusbar_class object must have a @window_class parent. */
|
/* Each @statusbar_class object must have a @window_class parent. */
|
||||||
JSClass statusbar_class = {
|
JSClass statusbar_class = {
|
||||||
"statusbar",
|
"statusbar",
|
||||||
JSCLASS_HAS_PRIVATE, /* const char * "s" */
|
JSCLASS_HAS_PRIVATE, /* const char * "s" */
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
JS_PropertyStub, JS_StrictPropertyStub,
|
JS_PropertyStub, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL
|
nullptr, nullptr, nullptr, nullptr
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Tinyids of properties. Use negative values to distinguish these
|
/* Tinyids of properties. Use negative values to distinguish these
|
||||||
|
@ -57,7 +57,7 @@ static inline int
|
|||||||
jsval_to_boolean(JSContext *ctx, jsval *vp)
|
jsval_to_boolean(JSContext *ctx, jsval *vp)
|
||||||
{
|
{
|
||||||
JS::RootedValue r_vp(ctx, *vp);
|
JS::RootedValue r_vp(ctx, *vp);
|
||||||
return (int)JS::ToBoolean(r_vp);
|
return (int)r_vp.toBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -55,9 +55,9 @@ static bool window_get_property_top(JSContext *ctx, unsigned int argc, jsval *vp
|
|||||||
JSClass window_class = {
|
JSClass window_class = {
|
||||||
"window",
|
"window",
|
||||||
JSCLASS_HAS_PRIVATE | JSCLASS_GLOBAL_FLAGS, /* struct view_state * */
|
JSCLASS_HAS_PRIVATE | JSCLASS_GLOBAL_FLAGS, /* struct view_state * */
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
window_get_property, JS_StrictPropertyStub,
|
window_get_property, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL
|
nullptr, nullptr, nullptr, nullptr
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -432,7 +432,7 @@ window_setTimeout(JSContext *ctx, unsigned int argc, jsval *rval)
|
|||||||
code = stracpy(code);
|
code = stracpy(code);
|
||||||
if (!code)
|
if (!code)
|
||||||
return true;
|
return true;
|
||||||
timeout = atoi(jsval_to_string(ctx, args[1].address()));
|
timeout = args[1].toInt32();
|
||||||
if (timeout <= 0) {
|
if (timeout <= 0) {
|
||||||
mem_free(code);
|
mem_free(code);
|
||||||
return true;
|
return true;
|
||||||
|
@ -29,9 +29,9 @@ static bool smjs_action_fn_callback(JSContext *ctx, unsigned int argc, jsval *rv
|
|||||||
static const JSClass action_fn_class = {
|
static const JSClass action_fn_class = {
|
||||||
"action_fn",
|
"action_fn",
|
||||||
JSCLASS_HAS_PRIVATE, /* struct smjs_action_fn_callback_hop * */
|
JSCLASS_HAS_PRIVATE, /* struct smjs_action_fn_callback_hop * */
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
JS_PropertyStub, JS_StrictPropertyStub,
|
JS_PropertyStub, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub,
|
nullptr, nullptr, nullptr,
|
||||||
smjs_action_fn_finalize,
|
smjs_action_fn_finalize,
|
||||||
NULL,
|
NULL,
|
||||||
smjs_action_fn_callback,
|
smjs_action_fn_callback,
|
||||||
@ -111,11 +111,8 @@ smjs_action_fn_callback(JSContext *ctx, unsigned int argc, jsval *rval)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (argc >= 1) {
|
if (argc >= 1) {
|
||||||
int32_t val;
|
int32_t val = args[0].toInt32();
|
||||||
|
set_kbd_repeat_count(hop->ses, val);
|
||||||
if (true == JS::ToInt32(smjs_ctx, args[0], &val)) {
|
|
||||||
set_kbd_repeat_count(hop->ses, val);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
do_action(hop->ses, hop->action_id, 1);
|
do_action(hop->ses, hop->action_id, 1);
|
||||||
@ -134,7 +131,7 @@ smjs_get_action_fn_object(unsigned char *action_str)
|
|||||||
|
|
||||||
if (!smjs_ses) return NULL;
|
if (!smjs_ses) return NULL;
|
||||||
|
|
||||||
obj = JS_NewObject(smjs_ctx, (JSClass *) &action_fn_class, JS::NullPtr(), JS::NullPtr());
|
obj = JS_NewObject(smjs_ctx, (JSClass *) &action_fn_class);
|
||||||
if (!obj) return NULL;
|
if (!obj) return NULL;
|
||||||
|
|
||||||
hop = mem_alloc(sizeof(*hop));
|
hop = mem_alloc(sizeof(*hop));
|
||||||
@ -175,7 +172,7 @@ action_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS:
|
|||||||
hvp.setNull();
|
hvp.setNull();
|
||||||
|
|
||||||
JS_IdToValue(ctx, id, &rval);
|
JS_IdToValue(ctx, id, &rval);
|
||||||
action_str = JS_EncodeString(ctx, JS::ToString(ctx, rval));
|
action_str = JS_EncodeString(ctx, rval.toString());
|
||||||
if (!action_str) return true;
|
if (!action_str) return true;
|
||||||
|
|
||||||
action_fn = smjs_get_action_fn_object(action_str);
|
action_fn = smjs_get_action_fn_object(action_str);
|
||||||
@ -189,9 +186,9 @@ action_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS:
|
|||||||
static const JSClass action_class = {
|
static const JSClass action_class = {
|
||||||
"action",
|
"action",
|
||||||
0,
|
0,
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
action_get_property, JS_StrictPropertyStub,
|
action_get_property, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL,
|
nullptr, nullptr, nullptr, nullptr,
|
||||||
};
|
};
|
||||||
|
|
||||||
static JSObject *
|
static JSObject *
|
||||||
@ -201,7 +198,7 @@ smjs_get_action_object(void)
|
|||||||
|
|
||||||
assert(smjs_ctx);
|
assert(smjs_ctx);
|
||||||
|
|
||||||
obj = JS_NewObject(smjs_ctx, (JSClass *) &action_class, JS::NullPtr(), JS::NullPtr());
|
obj = JS_NewObject(smjs_ctx, (JSClass *) &action_class);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -23,17 +23,17 @@ static bool bookmark_folder_get_property(JSContext *ctx, JS::HandleObject hobj,
|
|||||||
static const JSClass bookmark_class = {
|
static const JSClass bookmark_class = {
|
||||||
"bookmark",
|
"bookmark",
|
||||||
JSCLASS_HAS_PRIVATE, /* struct bookmark * */
|
JSCLASS_HAS_PRIVATE, /* struct bookmark * */
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
JS_PropertyStub, JS_StrictPropertyStub,
|
JS_PropertyStub, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, bookmark_finalize,
|
nullptr, nullptr, nullptr, bookmark_finalize,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const JSClass bookmark_folder_class = {
|
static const JSClass bookmark_folder_class = {
|
||||||
"bookmark_folder",
|
"bookmark_folder",
|
||||||
JSCLASS_HAS_PRIVATE, /* struct bookmark * */
|
JSCLASS_HAS_PRIVATE, /* struct bookmark * */
|
||||||
JS_PropertyStub, JS_PropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
bookmark_folder_get_property, JS_StrictPropertyStub,
|
bookmark_folder_get_property, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, bookmark_finalize,
|
nullptr, nullptr, nullptr, bookmark_finalize,
|
||||||
};
|
};
|
||||||
|
|
||||||
static JSObject *
|
static JSObject *
|
||||||
@ -44,7 +44,7 @@ smjs_get_bookmark_generic_object(struct bookmark *bookmark, JSClass *clasp)
|
|||||||
assert(clasp == &bookmark_class || clasp == &bookmark_folder_class);
|
assert(clasp == &bookmark_class || clasp == &bookmark_folder_class);
|
||||||
if_assert_failed return NULL;
|
if_assert_failed return NULL;
|
||||||
|
|
||||||
jsobj = JS_NewObject(smjs_ctx, clasp, JS::NullPtr(), JS::NullPtr());
|
jsobj = JS_NewObject(smjs_ctx, clasp);
|
||||||
if (!jsobj) return NULL;
|
if (!jsobj) return NULL;
|
||||||
|
|
||||||
if (!bookmark) return jsobj;
|
if (!bookmark) return jsobj;
|
||||||
@ -131,13 +131,15 @@ jsval_to_bookmark_string(JSContext *ctx, JS::HandleValue val, unsigned char **re
|
|||||||
{
|
{
|
||||||
unsigned char *str;
|
unsigned char *str;
|
||||||
|
|
||||||
JSString *jsstr = JS::ToString(ctx, val);
|
JSString *jsstr = val.toString();
|
||||||
|
|
||||||
if (jsstr == NULL) {
|
if (jsstr == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
str = jsstring_to_utf8(ctx, jsstr, NULL);
|
JS::RootedString r_jsstr(ctx, jsstr);
|
||||||
|
str = JS_EncodeStringToUTF8(ctx, r_jsstr);
|
||||||
|
|
||||||
if (str == NULL) {
|
if (str == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,9 @@ static void cache_entry_finalize(JSFreeOp *op, JSObject *obj);
|
|||||||
static const JSClass cache_entry_class = {
|
static const JSClass cache_entry_class = {
|
||||||
"cache_entry",
|
"cache_entry",
|
||||||
JSCLASS_HAS_PRIVATE, /* struct cache_entry *; a weak reference */
|
JSCLASS_HAS_PRIVATE, /* struct cache_entry *; a weak reference */
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
JS_PropertyStub, JS_StrictPropertyStub,
|
JS_PropertyStub, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, cache_entry_finalize
|
nullptr, nullptr, nullptr, cache_entry_finalize
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Tinyids of properties. Use negative values to distinguish these
|
/* Tinyids of properties. Use negative values to distinguish these
|
||||||
@ -129,7 +129,7 @@ cache_entry_set_property_content(JSContext *ctx, unsigned int argc, jsval *vp)
|
|||||||
* eventually unlock the object. */
|
* eventually unlock the object. */
|
||||||
object_lock(cached);
|
object_lock(cached);
|
||||||
|
|
||||||
jsstr = JS::ToString(smjs_ctx, args[0]);
|
jsstr = args[0].toString();
|
||||||
str = JS_EncodeString(smjs_ctx, jsstr);
|
str = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
len = JS_GetStringLength(jsstr);
|
len = JS_GetStringLength(jsstr);
|
||||||
add_fragment(cached, 0, str, len);
|
add_fragment(cached, 0, str, len);
|
||||||
@ -200,7 +200,7 @@ cache_entry_set_property_type(JSContext *ctx, unsigned int argc, jsval *vp)
|
|||||||
* eventually unlock the object. */
|
* eventually unlock the object. */
|
||||||
object_lock(cached);
|
object_lock(cached);
|
||||||
|
|
||||||
jsstr = JS::ToString(smjs_ctx, args[0]);
|
jsstr = args[0].toString();
|
||||||
str = JS_EncodeString(smjs_ctx, jsstr);
|
str = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
mem_free_set(&cached->content_type, stracpy(str));
|
mem_free_set(&cached->content_type, stracpy(str));
|
||||||
|
|
||||||
@ -253,8 +253,7 @@ smjs_get_cache_entry_object(struct cache_entry *cached)
|
|||||||
if_assert_failed return NULL;
|
if_assert_failed return NULL;
|
||||||
|
|
||||||
cache_entry_object = JS_NewObject(smjs_ctx,
|
cache_entry_object = JS_NewObject(smjs_ctx,
|
||||||
(JSClass *) &cache_entry_class,
|
(JSClass *) &cache_entry_class);
|
||||||
JS::NullPtr(), JS::NullPtr());
|
|
||||||
|
|
||||||
if (!cache_entry_object) return NULL;
|
if (!cache_entry_object) return NULL;
|
||||||
|
|
||||||
@ -390,7 +389,7 @@ cache_entry_set_property_head(JSContext *ctx, unsigned int argc, jsval *vp)
|
|||||||
* eventually unlock the object. */
|
* eventually unlock the object. */
|
||||||
object_lock(cached);
|
object_lock(cached);
|
||||||
|
|
||||||
jsstr = JS::ToString(smjs_ctx, args[0]);
|
jsstr = args[0].toString();
|
||||||
str = JS_EncodeString(smjs_ctx, jsstr);
|
str = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
mem_free_set(&cached->head, stracpy(str));
|
mem_free_set(&cached->head, stracpy(str));
|
||||||
|
|
||||||
|
@ -83,9 +83,11 @@ smjs_do_file(unsigned char *path)
|
|||||||
JS::RootedValue rval(smjs_ctx, val);
|
JS::RootedValue rval(smjs_ctx, val);
|
||||||
JS::RootedObject cg(smjs_ctx, JS::CurrentGlobalOrNull(smjs_ctx));
|
JS::RootedObject cg(smjs_ctx, JS::CurrentGlobalOrNull(smjs_ctx));
|
||||||
|
|
||||||
|
JS::CompileOptions options(smjs_ctx);
|
||||||
|
|
||||||
if (!add_file_to_string(&script, path)
|
if (!add_file_to_string(&script, path)
|
||||||
|| false == JS_EvaluateScript(smjs_ctx, cg,
|
|| false == JS::Evaluate(smjs_ctx, cg, options,
|
||||||
script.source, script.length, path, 1, &rval)) {
|
script.source, script.length, &rval)) {
|
||||||
alert_smjs_error("error loading script file");
|
alert_smjs_error("error loading script file");
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
@ -100,7 +102,7 @@ smjs_do_file_wrapper(JSContext *ctx, unsigned int argc, jsval *rval)
|
|||||||
{
|
{
|
||||||
JS::CallArgs args = CallArgsFromVp(argc, rval);
|
JS::CallArgs args = CallArgsFromVp(argc, rval);
|
||||||
|
|
||||||
JSString *jsstr = JS::ToString(smjs_ctx, args[0]);
|
JSString *jsstr = args[0].toString();
|
||||||
unsigned char *path = JS_EncodeString(smjs_ctx, jsstr);
|
unsigned char *path = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
|
|
||||||
if (smjs_do_file(path))
|
if (smjs_do_file(path))
|
||||||
@ -139,7 +141,7 @@ init_smjs(struct module *module)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_SetErrorReporter(smjs_ctx, error_reporter);
|
JS_SetErrorReporter(spidermonkey_runtime, error_reporter);
|
||||||
|
|
||||||
smjs_init_global_object();
|
smjs_init_global_object();
|
||||||
|
|
||||||
@ -188,7 +190,7 @@ utf8_to_jsstring(JSContext *ctx, const unsigned char *str, int length)
|
|||||||
size_t in_bytes;
|
size_t in_bytes;
|
||||||
const unsigned char *in_end;
|
const unsigned char *in_end;
|
||||||
size_t utf16_alloc;
|
size_t utf16_alloc;
|
||||||
jschar *utf16;
|
char16_t *utf16;
|
||||||
size_t utf16_used;
|
size_t utf16_used;
|
||||||
JSString *jsstr;
|
JSString *jsstr;
|
||||||
|
|
||||||
@ -200,7 +202,7 @@ utf8_to_jsstring(JSContext *ctx, const unsigned char *str, int length)
|
|||||||
/* Each byte of input can become at most one UTF-16 unit.
|
/* Each byte of input can become at most one UTF-16 unit.
|
||||||
* Check whether the multiplication could overflow. */
|
* Check whether the multiplication could overflow. */
|
||||||
assert(!needs_utf16_surrogates(UCS_REPLACEMENT_CHARACTER));
|
assert(!needs_utf16_surrogates(UCS_REPLACEMENT_CHARACTER));
|
||||||
if (in_bytes > ((size_t) -1) / sizeof(jschar)) {
|
if (in_bytes > ((size_t) -1) / sizeof(char16_t)) {
|
||||||
#ifdef HAVE_JS_REPORTALLOCATIONOVERFLOW
|
#ifdef HAVE_JS_REPORTALLOCATIONOVERFLOW
|
||||||
JS_ReportAllocationOverflow(ctx);
|
JS_ReportAllocationOverflow(ctx);
|
||||||
#else
|
#else
|
||||||
@ -211,7 +213,7 @@ utf8_to_jsstring(JSContext *ctx, const unsigned char *str, int length)
|
|||||||
utf16_alloc = in_bytes;
|
utf16_alloc = in_bytes;
|
||||||
/* Use malloc because SpiderMonkey will handle the memory after
|
/* Use malloc because SpiderMonkey will handle the memory after
|
||||||
* this routine finishes. */
|
* this routine finishes. */
|
||||||
utf16 = malloc(utf16_alloc * sizeof(jschar));
|
utf16 = malloc(utf16_alloc * sizeof(char16_t));
|
||||||
if (utf16 == NULL) {
|
if (utf16 == NULL) {
|
||||||
JS_ReportOutOfMemory(ctx);
|
JS_ReportOutOfMemory(ctx);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -247,22 +249,22 @@ utf8_to_jsstring(JSContext *ctx, const unsigned char *str, int length)
|
|||||||
return jsstr;
|
return jsstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Convert a jschar array to UTF-8 and append it to struct string.
|
/** Convert a char16_t array to UTF-8 and append it to struct string.
|
||||||
* Replace misused surrogate codepoints with UCS_REPLACEMENT_CHARACTER.
|
* Replace misused surrogate codepoints with UCS_REPLACEMENT_CHARACTER.
|
||||||
*
|
*
|
||||||
* @param[in,out] utf8
|
* @param[in,out] utf8
|
||||||
* The function appends characters to this UTF-8 string.
|
* The function appends characters to this UTF-8 string.
|
||||||
*
|
*
|
||||||
* @param[in] utf16
|
* @param[in] utf16
|
||||||
* Pointer to the first element in an array of jschars.
|
* Pointer to the first element in an array of char16_ts.
|
||||||
*
|
*
|
||||||
* @param[in] len
|
* @param[in] len
|
||||||
* Number of jschars in the @a utf16 array.
|
* Number of char16_ts in the @a utf16 array.
|
||||||
*
|
*
|
||||||
* @return @a utf8 if successful, or NULL if not. */
|
* @return @a utf8 if successful, or NULL if not. */
|
||||||
static struct string *
|
static struct string *
|
||||||
add_jschars_to_utf8_string(struct string *utf8,
|
add_jschars_to_utf8_string(struct string *utf8,
|
||||||
const jschar *utf16, size_t len)
|
const char16_t *utf16, size_t len)
|
||||||
{
|
{
|
||||||
size_t pos;
|
size_t pos;
|
||||||
|
|
||||||
@ -309,11 +311,11 @@ unsigned char *
|
|||||||
jsstring_to_utf8(JSContext *ctx, JSString *jsstr, int *length)
|
jsstring_to_utf8(JSContext *ctx, JSString *jsstr, int *length)
|
||||||
{
|
{
|
||||||
size_t utf16_len;
|
size_t utf16_len;
|
||||||
const jschar *utf16;
|
const char16_t *utf16;
|
||||||
struct string utf8;
|
struct string utf8;
|
||||||
|
|
||||||
utf16_len = JS_GetStringLength(jsstr);
|
utf16_len = JS_GetStringLength(jsstr);
|
||||||
utf16 = JS_GetStringCharsZ(ctx, jsstr); /* stays owned by jsstr */
|
utf16 = JS_GetTwoByteExternalStringChars(jsstr); /* stays owned by jsstr */
|
||||||
if (utf16 == NULL) {
|
if (utf16 == NULL) {
|
||||||
/* JS_GetStringChars doesn't have a JSContext *
|
/* JS_GetStringChars doesn't have a JSContext *
|
||||||
* parameter so it can't report the error
|
* parameter so it can't report the error
|
||||||
|
@ -111,9 +111,9 @@ static bool elinks_set_property(JSContext *ctx, JS::HandleObject hobj, JS::Handl
|
|||||||
static const JSClass elinks_class = {
|
static const JSClass elinks_class = {
|
||||||
"elinks",
|
"elinks",
|
||||||
0,
|
0,
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
elinks_get_property, elinks_set_property,
|
elinks_get_property, elinks_set_property,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL
|
nullptr, nullptr, nullptr, nullptr
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ elinks_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, boo
|
|||||||
|
|
||||||
if (!smjs_ses) return false;
|
if (!smjs_ses) return false;
|
||||||
|
|
||||||
jsstr = JS::ToString(smjs_ctx, hvp);
|
jsstr = hvp.toString();
|
||||||
if (!jsstr) return false;
|
if (!jsstr) return false;
|
||||||
|
|
||||||
url = JS_EncodeString(smjs_ctx, jsstr);
|
url = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
@ -332,7 +332,7 @@ elinks_set_property_location(JSContext *ctx, unsigned int argc, jsval *vp)
|
|||||||
|
|
||||||
if (!smjs_ses) return false;
|
if (!smjs_ses) return false;
|
||||||
|
|
||||||
jsstr = JS::ToString(smjs_ctx, args[0]);
|
jsstr = args[0].toString();
|
||||||
if (!jsstr) return false;
|
if (!jsstr) return false;
|
||||||
|
|
||||||
url = JS_EncodeString(smjs_ctx, jsstr);
|
url = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
|
@ -18,9 +18,9 @@ JSObject *smjs_global_object;
|
|||||||
|
|
||||||
static const JSClass global_class = {
|
static const JSClass global_class = {
|
||||||
"global", JSCLASS_GLOBAL_FLAGS,
|
"global", JSCLASS_GLOBAL_FLAGS,
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
JS_PropertyStub, JS_StrictPropertyStub,
|
JS_PropertyStub, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL
|
nullptr, nullptr, nullptr, nullptr
|
||||||
};
|
};
|
||||||
|
|
||||||
static JSObject *
|
static JSObject *
|
||||||
|
@ -20,9 +20,9 @@ static void smjs_globhist_item_finalize(JSFreeOp *op, JSObject *obj);
|
|||||||
static const JSClass smjs_globhist_item_class = {
|
static const JSClass smjs_globhist_item_class = {
|
||||||
"global_history_item",
|
"global_history_item",
|
||||||
JSCLASS_HAS_PRIVATE, /* struct global_history_item * */
|
JSCLASS_HAS_PRIVATE, /* struct global_history_item * */
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
smjs_globhist_item_get_property, smjs_globhist_item_set_property,
|
smjs_globhist_item_get_property, smjs_globhist_item_set_property,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub,
|
nullptr, nullptr, nullptr,
|
||||||
smjs_globhist_item_finalize,
|
smjs_globhist_item_finalize,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ smjs_globhist_item_set_property(JSContext *ctx, JS::HandleObject hobj, JS::Handl
|
|||||||
|
|
||||||
switch (JSID_TO_INT(id)) {
|
switch (JSID_TO_INT(id)) {
|
||||||
case GLOBHIST_TITLE: {
|
case GLOBHIST_TITLE: {
|
||||||
JSString *jsstr = JS::ToString(smjs_ctx, hvp);
|
JSString *jsstr = hvp.toString();
|
||||||
unsigned char *str = JS_EncodeString(smjs_ctx, jsstr);
|
unsigned char *str = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
|
|
||||||
mem_free_set(&history_item->title, stracpy(str));
|
mem_free_set(&history_item->title, stracpy(str));
|
||||||
@ -164,7 +164,7 @@ smjs_globhist_item_set_property(JSContext *ctx, JS::HandleObject hobj, JS::Handl
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case GLOBHIST_URL: {
|
case GLOBHIST_URL: {
|
||||||
JSString *jsstr = JS::ToString(smjs_ctx, hvp);
|
JSString *jsstr = hvp.toString();
|
||||||
unsigned char *str = JS_EncodeString(smjs_ctx, jsstr);
|
unsigned char *str = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
|
|
||||||
mem_free_set(&history_item->url, stracpy(str));
|
mem_free_set(&history_item->url, stracpy(str));
|
||||||
@ -172,11 +172,8 @@ smjs_globhist_item_set_property(JSContext *ctx, JS::HandleObject hobj, JS::Handl
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case GLOBHIST_LAST_VISIT: {
|
case GLOBHIST_LAST_VISIT: {
|
||||||
uint32_t seconds;
|
|
||||||
|
|
||||||
/* Bug 923: Assumes time_t values fit in uint32. */
|
/* Bug 923: Assumes time_t values fit in uint32. */
|
||||||
JS::ToInt32(smjs_ctx, hvp, &seconds);
|
history_item->last_visit = hvp.toInt32();
|
||||||
history_item->last_visit = seconds;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -195,8 +192,7 @@ smjs_get_globhist_item_object(struct global_history_item *history_item)
|
|||||||
{
|
{
|
||||||
JSObject *jsobj;
|
JSObject *jsobj;
|
||||||
|
|
||||||
jsobj = JS_NewObject(smjs_ctx, (JSClass *) &smjs_globhist_item_class,
|
jsobj = JS_NewObject(smjs_ctx, (JSClass *) &smjs_globhist_item_class);
|
||||||
JS::NullPtr(), JS::NullPtr());
|
|
||||||
|
|
||||||
JS::RootedObject r_jsobj(smjs_ctx, jsobj);
|
JS::RootedObject r_jsobj(smjs_ctx, jsobj);
|
||||||
|
|
||||||
@ -228,7 +224,7 @@ smjs_globhist_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h
|
|||||||
if (!JS_IdToValue(ctx, id, &r_tmp))
|
if (!JS_IdToValue(ctx, id, &r_tmp))
|
||||||
goto ret_null;
|
goto ret_null;
|
||||||
|
|
||||||
uri_string = JS_EncodeString(ctx, JS::ToString(ctx, r_tmp));
|
uri_string = JS_EncodeString(ctx, r_tmp.toString());
|
||||||
if (!uri_string) goto ret_null;
|
if (!uri_string) goto ret_null;
|
||||||
|
|
||||||
history_item = get_global_history_item(uri_string);
|
history_item = get_global_history_item(uri_string);
|
||||||
@ -249,9 +245,9 @@ ret_null:
|
|||||||
|
|
||||||
static const JSClass smjs_globhist_class = {
|
static const JSClass smjs_globhist_class = {
|
||||||
"global_history", 0,
|
"global_history", 0,
|
||||||
JS_PropertyStub, JS_PropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
smjs_globhist_get_property, JS_StrictPropertyStub,
|
smjs_globhist_get_property, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL,
|
nullptr, nullptr, nullptr, nullptr
|
||||||
};
|
};
|
||||||
|
|
||||||
static JSObject *
|
static JSObject *
|
||||||
@ -259,8 +255,7 @@ smjs_get_globhist_object(void)
|
|||||||
{
|
{
|
||||||
JSObject *globhist;
|
JSObject *globhist;
|
||||||
|
|
||||||
globhist = JS_NewObject(smjs_ctx, (JSClass *) &smjs_globhist_class,
|
globhist = JS_NewObject(smjs_ctx, (JSClass *) &smjs_globhist_class);
|
||||||
JS::NullPtr(), JS::NullPtr());
|
|
||||||
if (!globhist) return NULL;
|
if (!globhist) return NULL;
|
||||||
|
|
||||||
return globhist;
|
return globhist;
|
||||||
@ -332,7 +327,7 @@ smjs_globhist_item_set_property_title(JSContext *ctx, unsigned int argc, jsval *
|
|||||||
|
|
||||||
if (!history_item) return false;
|
if (!history_item) return false;
|
||||||
|
|
||||||
jsstr = JS::ToString(smjs_ctx, args[0]);
|
jsstr = args[0].toString();
|
||||||
str = JS_EncodeString(smjs_ctx, jsstr);
|
str = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
mem_free_set(&history_item->title, stracpy(str));
|
mem_free_set(&history_item->title, stracpy(str));
|
||||||
|
|
||||||
@ -386,7 +381,7 @@ smjs_globhist_item_set_property_url(JSContext *ctx, unsigned int argc, jsval *vp
|
|||||||
|
|
||||||
if (!history_item) return false;
|
if (!history_item) return false;
|
||||||
|
|
||||||
jsstr = JS::ToString(smjs_ctx, args[0]);
|
jsstr = args[0].toString();
|
||||||
str = JS_EncodeString(smjs_ctx, jsstr);
|
str = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
mem_free_set(&history_item->url, stracpy(str));
|
mem_free_set(&history_item->url, stracpy(str));
|
||||||
|
|
||||||
@ -442,7 +437,6 @@ smjs_globhist_item_set_property_last_visit(JSContext *ctx, unsigned int argc, js
|
|||||||
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
struct global_history_item *history_item;
|
struct global_history_item *history_item;
|
||||||
uint32_t seconds;
|
|
||||||
|
|
||||||
/* This can be called if @obj if not itself an instance of the
|
/* This can be called if @obj if not itself an instance of the
|
||||||
* appropriate class but has one in its prototype chain. Fail
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
@ -457,8 +451,7 @@ smjs_globhist_item_set_property_last_visit(JSContext *ctx, unsigned int argc, js
|
|||||||
if (!history_item) return false;
|
if (!history_item) return false;
|
||||||
|
|
||||||
/* Bug 923: Assumes time_t values fit in uint32. */
|
/* Bug 923: Assumes time_t values fit in uint32. */
|
||||||
JS::ToInt32(smjs_ctx, args[0], &seconds);
|
history_item->last_visit = args[0].toInt32();
|
||||||
history_item->last_visit = seconds;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ script_hook_url(va_list ap, void *data)
|
|||||||
if (false == (r_rval.toBoolean()))
|
if (false == (r_rval.toBoolean()))
|
||||||
ret = EVENT_HOOK_STATUS_LAST;
|
ret = EVENT_HOOK_STATUS_LAST;
|
||||||
} else {
|
} else {
|
||||||
JSString *jsstr = JS::ToString(smjs_ctx, r_rval);
|
JSString *jsstr = r_rval.toString();
|
||||||
unsigned char *str = JS_EncodeString(smjs_ctx, jsstr);
|
unsigned char *str = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
|
|
||||||
mem_free_set(url, stracpy(str));
|
mem_free_set(url, stracpy(str));
|
||||||
@ -82,7 +82,7 @@ script_hook_pre_format_html(va_list ap, void *data)
|
|||||||
|
|
||||||
if (true == smjs_invoke_elinks_object_method("preformat_html",
|
if (true == smjs_invoke_elinks_object_method("preformat_html",
|
||||||
2, args, &r_rval))
|
2, args, &r_rval))
|
||||||
if (false == JSVAL_TO_BOOLEAN(rval))
|
if (false == r_rval.toBoolean())
|
||||||
ret = EVENT_HOOK_STATUS_LAST;
|
ret = EVENT_HOOK_STATUS_LAST;
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
@ -20,9 +20,9 @@ static void keymap_finalize(JSFreeOp *op, JSObject *obj);
|
|||||||
static const JSClass keymap_class = {
|
static const JSClass keymap_class = {
|
||||||
"keymap",
|
"keymap",
|
||||||
JSCLASS_HAS_PRIVATE, /* int * */
|
JSCLASS_HAS_PRIVATE, /* int * */
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
keymap_get_property, keymap_set_property,
|
keymap_get_property, keymap_set_property,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, keymap_finalize,
|
nullptr, nullptr, nullptr, keymap_finalize,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* @keymap_class.getProperty */
|
/* @keymap_class.getProperty */
|
||||||
@ -49,7 +49,7 @@ keymap_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS:
|
|||||||
if (!JS_IdToValue(ctx, id, &r_tmp))
|
if (!JS_IdToValue(ctx, id, &r_tmp))
|
||||||
goto ret_null;
|
goto ret_null;
|
||||||
|
|
||||||
keystroke_str = JS_EncodeString(ctx, JS::ToString(ctx, r_tmp));
|
keystroke_str = JS_EncodeString(ctx, r_tmp.toString());
|
||||||
if (!keystroke_str) goto ret_null;
|
if (!keystroke_str) goto ret_null;
|
||||||
|
|
||||||
action_str = get_action_name_from_keystroke((enum keymap_id) *data,
|
action_str = get_action_name_from_keystroke((enum keymap_id) *data,
|
||||||
@ -119,13 +119,13 @@ keymap_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, boo
|
|||||||
|
|
||||||
JS::RootedValue rval(ctx, val);
|
JS::RootedValue rval(ctx, val);
|
||||||
JS_IdToValue(ctx, id, &rval);
|
JS_IdToValue(ctx, id, &rval);
|
||||||
keystroke_str = JS_EncodeString(ctx, JS::ToString(ctx, rval));
|
keystroke_str = JS_EncodeString(ctx, rval.toString());
|
||||||
if (!keystroke_str) return false;
|
if (!keystroke_str) return false;
|
||||||
|
|
||||||
if (hvp.isString()) {
|
if (hvp.isString()) {
|
||||||
unsigned char *action_str;
|
unsigned char *action_str;
|
||||||
|
|
||||||
action_str = JS_EncodeString(ctx, JS::ToString(ctx, hvp));
|
action_str = JS_EncodeString(ctx, hvp.toString());
|
||||||
if (!action_str) return false;
|
if (!action_str) return false;
|
||||||
|
|
||||||
if (bind_do(keymap_str, keystroke_str, action_str, 0))
|
if (bind_do(keymap_str, keystroke_str, action_str, 0))
|
||||||
@ -204,8 +204,7 @@ smjs_get_keymap_object(enum keymap_id keymap_id)
|
|||||||
|
|
||||||
assert(smjs_ctx);
|
assert(smjs_ctx);
|
||||||
|
|
||||||
keymap_object = JS_NewObject(smjs_ctx, (JSClass *) &keymap_class,
|
keymap_object = JS_NewObject(smjs_ctx, (JSClass *) &keymap_class);
|
||||||
JS::NullPtr(),JS::NullPtr());
|
|
||||||
|
|
||||||
if (!keymap_object) return NULL;
|
if (!keymap_object) return NULL;
|
||||||
|
|
||||||
@ -219,9 +218,9 @@ smjs_get_keymap_object(enum keymap_id keymap_id)
|
|||||||
static const JSClass keymaps_hash_class = {
|
static const JSClass keymaps_hash_class = {
|
||||||
"keymaps_hash",
|
"keymaps_hash",
|
||||||
JSCLASS_HAS_PRIVATE,
|
JSCLASS_HAS_PRIVATE,
|
||||||
JS_PropertyStub, JS_PropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
JS_PropertyStub, JS_StrictPropertyStub,
|
JS_PropertyStub, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL,
|
nullptr, nullptr, nullptr, nullptr,
|
||||||
};
|
};
|
||||||
|
|
||||||
static JSObject *
|
static JSObject *
|
||||||
@ -231,8 +230,7 @@ smjs_get_keymap_hash_object(void)
|
|||||||
int keymap_id;
|
int keymap_id;
|
||||||
JSObject *keymaps_hash;
|
JSObject *keymaps_hash;
|
||||||
|
|
||||||
keymaps_hash = JS_NewObject(smjs_ctx, (JSClass *) &keymaps_hash_class,
|
keymaps_hash = JS_NewObject(smjs_ctx, (JSClass *) &keymaps_hash_class);
|
||||||
JS::NullPtr(), JS::NullPtr());
|
|
||||||
if (!keymaps_hash) return NULL;
|
if (!keymaps_hash) return NULL;
|
||||||
|
|
||||||
JS::RootedObject r_keymaps_hash(smjs_ctx, keymaps_hash);
|
JS::RootedObject r_keymaps_hash(smjs_ctx, keymaps_hash);
|
||||||
|
@ -83,7 +83,7 @@ smjs_load_uri(JSContext *ctx, unsigned int argc, jsval *rval)
|
|||||||
|
|
||||||
if (argc < 2) return false;
|
if (argc < 2) return false;
|
||||||
|
|
||||||
jsstr = JS::ToString(smjs_ctx, args[0]);
|
jsstr = args[0].toString();
|
||||||
uri_string = JS_EncodeString(smjs_ctx, jsstr);
|
uri_string = JS_EncodeString(smjs_ctx, jsstr);
|
||||||
if (!uri_string || !*uri_string) return false;
|
if (!uri_string || !*uri_string) return false;
|
||||||
|
|
||||||
|
@ -37,10 +37,10 @@ static bool session_construct(JSContext *ctx, unsigned int argc, jsval *rval);
|
|||||||
|
|
||||||
static const JSClass session_class = {
|
static const JSClass session_class = {
|
||||||
"session",
|
"session",
|
||||||
JSCLASS_HAS_PRIVATE, /* struct session *; a weak reference */
|
JSCLASS_HAS_PRIVATE | JSCLASS_IMPLEMENTS_BARRIERS, /* struct session *; a weak reference */
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
session_get_property, session_set_property,
|
session_get_property, session_set_property,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, session_finalize,
|
nullptr, nullptr, nullptr, session_finalize,
|
||||||
NULL, NULL, NULL, session_construct
|
NULL, NULL, NULL, session_construct
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -50,9 +50,9 @@ static void smjs_location_array_finalize(JSFreeOp *op, JSObject *obj);
|
|||||||
static const JSClass location_array_class = {
|
static const JSClass location_array_class = {
|
||||||
"location_array",
|
"location_array",
|
||||||
JSCLASS_HAS_PRIVATE, /* struct session *; a weak reference */
|
JSCLASS_HAS_PRIVATE, /* struct session *; a weak reference */
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
smjs_location_array_get_property, JS_StrictPropertyStub,
|
smjs_location_array_get_property, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, smjs_location_array_finalize,
|
nullptr, nullptr, nullptr, smjs_location_array_finalize,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* location_array_class is the class for array object, the elements of which
|
/* location_array_class is the class for array object, the elements of which
|
||||||
@ -148,7 +148,7 @@ smjs_get_session_location_array_object(struct session *ses)
|
|||||||
assert(smjs_ctx);
|
assert(smjs_ctx);
|
||||||
if_assert_failed return NULL;
|
if_assert_failed return NULL;
|
||||||
|
|
||||||
obj = JS_NewObject(smjs_ctx, (JSClass *) &location_array_class, JS::NullPtr(), JS::NullPtr());
|
obj = JS_NewObject(smjs_ctx, (JSClass *) &location_array_class);
|
||||||
if (!obj) return NULL;
|
if (!obj) return NULL;
|
||||||
|
|
||||||
/* Do this last, so that if any previous step fails, we can
|
/* Do this last, so that if any previous step fails, we can
|
||||||
@ -576,91 +576,6 @@ session_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX: Lock session here if it is ever changed to have an OBJECT_HEAD. */
|
|
||||||
|
|
||||||
hvp.setUndefined();
|
|
||||||
|
|
||||||
switch (JSID_TO_INT(id)) {
|
|
||||||
case SESSION_VISITED:
|
|
||||||
hvp.setInt32(ses->status.visited);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
case SESSION_HISTORY: {
|
|
||||||
JSObject *obj = smjs_get_session_location_array_object(ses);
|
|
||||||
|
|
||||||
if (obj) {
|
|
||||||
hvp.setObject(*obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case SESSION_LOADING_URI: {
|
|
||||||
struct uri *uri = have_location(ses) ? cur_loc(ses)->vs.uri
|
|
||||||
: ses->loading_uri;
|
|
||||||
|
|
||||||
if (uri) {
|
|
||||||
hvp.setString(JS_NewStringCopyZ(ctx, struri(uri)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case SESSION_RELOADLEVEL:
|
|
||||||
hvp.setInt32(ses->reloadlevel);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
case SESSION_REDIRECT_CNT:
|
|
||||||
hvp.setInt32(ses->redirect_cnt);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
case SESSION_SEARCH_DIRECTION:
|
|
||||||
hvp.setString(JS_NewStringCopyZ(ctx, ses->search_direction == 1 ? "down" : "up"));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
case SESSION_KBDPREFIX:
|
|
||||||
hvp.setInt32(ses->kbdprefix.repeat_count);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
case SESSION_MARK_WAITING_FOR:
|
|
||||||
hvp.setString(JS_NewStringCopyZ(ctx, ses->kbdprefix.mark == KP_MARK_NOTHING
|
|
||||||
? "nothing"
|
|
||||||
: ses->kbdprefix.mark == KP_MARK_SET
|
|
||||||
? "set"
|
|
||||||
: "goto"));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
case SESSION_EXIT_QUERY:
|
|
||||||
hvp.setInt32(ses->exit_query);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
case SESSION_INSERT_MODE:
|
|
||||||
hvp.setString(JS_NewStringCopyZ(ctx,
|
|
||||||
ses->insert_mode == INSERT_MODE_LESS
|
|
||||||
? "disabled"
|
|
||||||
: ses->insert_mode == INSERT_MODE_ON
|
|
||||||
? "on"
|
|
||||||
: "off"));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
case SESSION_NAVIGATE_MODE:
|
|
||||||
hvp.setString(JS_NewStringCopyZ(ctx,
|
|
||||||
ses->navigate_mode == NAVIGATE_CURSOR_ROUTING
|
|
||||||
? "cursor"
|
|
||||||
: "linkwise"));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
case SESSION_SEARCH_WORD:
|
|
||||||
hvp.setString(JS_NewStringCopyZ(ctx, ses->search_word));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
case SESSION_LAST_SEARCH_WORD:
|
|
||||||
hvp.setString(JS_NewStringCopyZ(ctx, ses->last_search_word));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
INTERNAL("Invalid ID %d in session_get_property().",
|
|
||||||
JSID_TO_INT(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -706,7 +621,7 @@ session_set_property_reloadlevel(JSContext *ctx, unsigned int argc, jsval *vp)
|
|||||||
(JSClass *) &session_class, NULL);
|
(JSClass *) &session_class, NULL);
|
||||||
if (!ses) return false;
|
if (!ses) return false;
|
||||||
|
|
||||||
JS::ToInt32(ctx, args[0], &ses->reloadlevel);
|
ses->reloadlevel = args[0].toInt32();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -729,7 +644,7 @@ session_set_property_redirect_cnt(JSContext *ctx, unsigned int argc, jsval *vp)
|
|||||||
(JSClass *) &session_class, NULL);
|
(JSClass *) &session_class, NULL);
|
||||||
if (!ses) return false;
|
if (!ses) return false;
|
||||||
|
|
||||||
JS::ToInt32(ctx, args[0], &ses->redirect_cnt);
|
ses->redirect_cnt = args[0].toInt32();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -755,7 +670,7 @@ session_set_property_search_direction(JSContext *ctx, unsigned int argc, jsval *
|
|||||||
unsigned char *str;
|
unsigned char *str;
|
||||||
JSString *jsstr;
|
JSString *jsstr;
|
||||||
|
|
||||||
jsstr = JS::ToString(ctx, args[0]);
|
jsstr = args[0].toString();
|
||||||
if (!jsstr) return true;
|
if (!jsstr) return true;
|
||||||
|
|
||||||
str = JS_EncodeString(ctx, jsstr);
|
str = JS_EncodeString(ctx, jsstr);
|
||||||
@ -789,7 +704,7 @@ session_set_property_kbdprefix(JSContext *ctx, unsigned int argc, jsval *vp)
|
|||||||
(JSClass *) &session_class, NULL);
|
(JSClass *) &session_class, NULL);
|
||||||
if (!ses) return false;
|
if (!ses) return false;
|
||||||
|
|
||||||
JS::ToInt32(ctx, args[0], &ses->kbdprefix.repeat_count);
|
ses->kbdprefix.repeat_count = args[0].toInt32();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -815,7 +730,7 @@ session_set_property_mark(JSContext *ctx, unsigned int argc, jsval *vp)
|
|||||||
unsigned char *str;
|
unsigned char *str;
|
||||||
JSString *jsstr;
|
JSString *jsstr;
|
||||||
|
|
||||||
jsstr = JS::ToString(ctx, args[0]);
|
jsstr = args[0].toString();
|
||||||
if (!jsstr) return true;
|
if (!jsstr) return true;
|
||||||
|
|
||||||
str = JS_EncodeString(ctx, jsstr);
|
str = JS_EncodeString(ctx, jsstr);
|
||||||
@ -854,7 +769,7 @@ session_set_property_insert_mode(JSContext *ctx, unsigned int argc, jsval *vp)
|
|||||||
unsigned char *str;
|
unsigned char *str;
|
||||||
JSString *jsstr;
|
JSString *jsstr;
|
||||||
|
|
||||||
jsstr = JS::ToString(ctx, args[0]);
|
jsstr = args[0].toString();
|
||||||
if (!jsstr) return true;
|
if (!jsstr) return true;
|
||||||
|
|
||||||
str = JS_EncodeString(ctx, jsstr);
|
str = JS_EncodeString(ctx, jsstr);
|
||||||
@ -893,7 +808,7 @@ session_set_property_navigate_mode(JSContext *ctx, unsigned int argc, jsval *vp)
|
|||||||
unsigned char *str;
|
unsigned char *str;
|
||||||
JSString *jsstr;
|
JSString *jsstr;
|
||||||
|
|
||||||
jsstr = JS::ToString(ctx, args[0]);
|
jsstr = args[0].toString();
|
||||||
if (!jsstr) return true;
|
if (!jsstr) return true;
|
||||||
|
|
||||||
str = JS_EncodeString(ctx, jsstr);
|
str = JS_EncodeString(ctx, jsstr);
|
||||||
@ -930,7 +845,7 @@ session_set_property_search_word(JSContext *ctx, unsigned int argc, jsval *vp)
|
|||||||
unsigned char *str;
|
unsigned char *str;
|
||||||
JSString *jsstr;
|
JSString *jsstr;
|
||||||
|
|
||||||
jsstr = JS::ToString(ctx, args[0]);
|
jsstr = args[0].toString();
|
||||||
if (!jsstr) return true;
|
if (!jsstr) return true;
|
||||||
|
|
||||||
str = JS_EncodeString(ctx, jsstr);
|
str = JS_EncodeString(ctx, jsstr);
|
||||||
@ -962,7 +877,7 @@ session_set_property_last_search_word(JSContext *ctx, unsigned int argc, jsval *
|
|||||||
unsigned char *str;
|
unsigned char *str;
|
||||||
JSString *jsstr;
|
JSString *jsstr;
|
||||||
|
|
||||||
jsstr = JS::ToString(ctx, args[0]);
|
jsstr = args[0].toString();
|
||||||
if (!jsstr) return true;
|
if (!jsstr) return true;
|
||||||
|
|
||||||
str = JS_EncodeString(ctx, jsstr);
|
str = JS_EncodeString(ctx, jsstr);
|
||||||
@ -995,141 +910,6 @@ session_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, bo
|
|||||||
if (!JSID_IS_INT(id))
|
if (!JSID_IS_INT(id))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch (JSID_TO_INT(id)) {
|
|
||||||
case SESSION_VISITED:
|
|
||||||
int v;
|
|
||||||
JS::ToInt32(ctx, hvp, &v);
|
|
||||||
ses->status.visited = v;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
/* SESSION_HISTORY is RO */
|
|
||||||
/* SESSION_LOADING_URI is RO */
|
|
||||||
case SESSION_RELOADLEVEL:
|
|
||||||
JS::ToInt32(ctx, hvp, &ses->reloadlevel);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
case SESSION_REDIRECT_CNT:
|
|
||||||
JS::ToInt32(ctx, hvp, &ses->redirect_cnt);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
case SESSION_SEARCH_DIRECTION: {
|
|
||||||
unsigned char *str;
|
|
||||||
JSString *jsstr;
|
|
||||||
|
|
||||||
jsstr = JS::ToString(ctx, hvp);
|
|
||||||
if (!jsstr) return true;
|
|
||||||
|
|
||||||
str = JS_EncodeString(ctx, jsstr);
|
|
||||||
if (!str) return true;
|
|
||||||
|
|
||||||
if (!strcmp(str, "up"))
|
|
||||||
ses->search_direction = -1;
|
|
||||||
else if (!strcmp(str, "down"))
|
|
||||||
ses->search_direction = 1;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case SESSION_KBDPREFIX:
|
|
||||||
JS::ToInt32(ctx, hvp, &ses->kbdprefix.repeat_count);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
case SESSION_MARK_WAITING_FOR: {
|
|
||||||
unsigned char *str;
|
|
||||||
JSString *jsstr;
|
|
||||||
|
|
||||||
jsstr = JS::ToString(ctx, hvp);
|
|
||||||
if (!jsstr) return true;
|
|
||||||
|
|
||||||
str = JS_EncodeString(ctx, jsstr);
|
|
||||||
if (!str) return true;
|
|
||||||
|
|
||||||
if (!strcmp(str, "nothing"))
|
|
||||||
ses->kbdprefix.mark = KP_MARK_NOTHING;
|
|
||||||
else if (!strcmp(str, "set"))
|
|
||||||
ses->kbdprefix.mark = KP_MARK_SET;
|
|
||||||
else if (!strcmp(str, "goto"))
|
|
||||||
ses->kbdprefix.mark = KP_MARK_GOTO;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/* SESSION_EXIT_QUERY is RO */
|
|
||||||
case SESSION_INSERT_MODE: {
|
|
||||||
unsigned char *str;
|
|
||||||
JSString *jsstr;
|
|
||||||
|
|
||||||
jsstr = JS::ToString(ctx, hvp);
|
|
||||||
if (!jsstr) return true;
|
|
||||||
|
|
||||||
str = JS_EncodeString(ctx, jsstr);
|
|
||||||
if (!str) return true;
|
|
||||||
|
|
||||||
if (!strcmp(str, "disabled"))
|
|
||||||
ses->insert_mode = INSERT_MODE_LESS;
|
|
||||||
else if (!strcmp(str, "on"))
|
|
||||||
ses->insert_mode = INSERT_MODE_ON;
|
|
||||||
else if (!strcmp(str, "off"))
|
|
||||||
ses->insert_mode = INSERT_MODE_OFF;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case SESSION_NAVIGATE_MODE: {
|
|
||||||
unsigned char *str;
|
|
||||||
JSString *jsstr;
|
|
||||||
|
|
||||||
jsstr = JS::ToString(ctx, hvp);
|
|
||||||
if (!jsstr) return true;
|
|
||||||
|
|
||||||
str = JS_EncodeString(ctx, jsstr);
|
|
||||||
if (!str) return true;
|
|
||||||
|
|
||||||
if (!strcmp(str, "cursor"))
|
|
||||||
ses->navigate_mode = NAVIGATE_CURSOR_ROUTING;
|
|
||||||
else if (!strcmp(str, "linkwise"))
|
|
||||||
ses->navigate_mode = NAVIGATE_LINKWISE;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case SESSION_SEARCH_WORD: {
|
|
||||||
unsigned char *str;
|
|
||||||
JSString *jsstr;
|
|
||||||
|
|
||||||
jsstr = JS::ToString(ctx, hvp);
|
|
||||||
if (!jsstr) return true;
|
|
||||||
|
|
||||||
str = JS_EncodeString(ctx, jsstr);
|
|
||||||
if (!str) return true;
|
|
||||||
|
|
||||||
mem_free_set(&ses->search_word, str);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case SESSION_LAST_SEARCH_WORD: {
|
|
||||||
unsigned char *str;
|
|
||||||
JSString *jsstr;
|
|
||||||
|
|
||||||
jsstr = JS::ToString(ctx, hvp);
|
|
||||||
if (!jsstr) return true;
|
|
||||||
|
|
||||||
str = JS_EncodeString(ctx, jsstr);
|
|
||||||
if (!str) return true;
|
|
||||||
|
|
||||||
mem_free_set(&ses->last_search_word, str);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
INTERNAL("Invalid ID %d in session_set_property().",
|
|
||||||
JSID_TO_INT(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1139,7 +919,7 @@ static bool
|
|||||||
session_construct(JSContext *ctx, unsigned int argc, jsval *rval)
|
session_construct(JSContext *ctx, unsigned int argc, jsval *rval)
|
||||||
{
|
{
|
||||||
JS::CallArgs args = CallArgsFromVp(argc, rval);
|
JS::CallArgs args = CallArgsFromVp(argc, rval);
|
||||||
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
//JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
jsval val;
|
jsval val;
|
||||||
int bg = 0; /* open new tab in background */
|
int bg = 0; /* open new tab in background */
|
||||||
@ -1204,7 +984,7 @@ smjs_get_session_object(struct session *ses)
|
|||||||
assert(smjs_ctx);
|
assert(smjs_ctx);
|
||||||
if_assert_failed return NULL;
|
if_assert_failed return NULL;
|
||||||
|
|
||||||
obj = JS_NewObject(smjs_ctx, (JSClass *) &session_class, JS::NullPtr(), JS::NullPtr());
|
obj = JS_NewObject(smjs_ctx, (JSClass *) &session_class);
|
||||||
if (!obj) return NULL;
|
if (!obj) return NULL;
|
||||||
|
|
||||||
JS::RootedObject r_obj(smjs_ctx, obj);
|
JS::RootedObject r_obj(smjs_ctx, obj);
|
||||||
@ -1299,9 +1079,9 @@ session_array_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h
|
|||||||
static const JSClass session_array_class = {
|
static const JSClass session_array_class = {
|
||||||
"session_array",
|
"session_array",
|
||||||
JSCLASS_HAS_PRIVATE, /* struct terminal *term; a weak reference */
|
JSCLASS_HAS_PRIVATE, /* struct terminal *term; a weak reference */
|
||||||
JS_PropertyStub, JS_PropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
session_array_get_property, JS_StrictPropertyStub,
|
session_array_get_property, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL
|
nullptr, nullptr, nullptr, nullptr
|
||||||
};
|
};
|
||||||
|
|
||||||
JSObject *
|
JSObject *
|
||||||
@ -1312,8 +1092,7 @@ smjs_get_session_array_object(struct terminal *term)
|
|||||||
assert(smjs_ctx);
|
assert(smjs_ctx);
|
||||||
if_assert_failed return NULL;
|
if_assert_failed return NULL;
|
||||||
|
|
||||||
obj = JS_NewObject(smjs_ctx, (JSClass *) &session_array_class,
|
obj = JS_NewObject(smjs_ctx, (JSClass *) &session_array_class);
|
||||||
JS::NullPtr(), JS::NullPtr());
|
|
||||||
if (!obj) return NULL;
|
if (!obj) return NULL;
|
||||||
|
|
||||||
JS_SetPrivate(obj, term);
|
JS_SetPrivate(obj, term);
|
||||||
@ -1365,7 +1144,7 @@ smjs_session_goto_url(JSContext *ctx, unsigned int argc, jsval *rval)
|
|||||||
(JSClass *) &session_class, NULL);
|
(JSClass *) &session_class, NULL);
|
||||||
if (!ses) return false; /* detached */
|
if (!ses) return false; /* detached */
|
||||||
|
|
||||||
jsstr = JS::ToString(ctx, args[0]);
|
jsstr = args[0].toString();
|
||||||
if (!jsstr) return false;
|
if (!jsstr) return false;
|
||||||
|
|
||||||
url = JS_EncodeString(ctx, jsstr);
|
url = JS_EncodeString(ctx, jsstr);
|
||||||
|
@ -23,9 +23,9 @@ static void terminal_finalize(JSFreeOp *op, JSObject *obj);
|
|||||||
static const JSClass terminal_class = {
|
static const JSClass terminal_class = {
|
||||||
"terminal",
|
"terminal",
|
||||||
JSCLASS_HAS_PRIVATE, /* struct terminal *; a weak refernce */
|
JSCLASS_HAS_PRIVATE, /* struct terminal *; a weak refernce */
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
terminal_get_property, JS_StrictPropertyStub,
|
terminal_get_property, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, terminal_finalize
|
nullptr, nullptr, nullptr, terminal_finalize
|
||||||
};
|
};
|
||||||
|
|
||||||
enum terminal_prop {
|
enum terminal_prop {
|
||||||
@ -112,7 +112,7 @@ smjs_get_terminal_object(struct terminal *term)
|
|||||||
assert(smjs_ctx);
|
assert(smjs_ctx);
|
||||||
if_assert_failed return NULL;
|
if_assert_failed return NULL;
|
||||||
|
|
||||||
obj = JS_NewObject(smjs_ctx, (JSClass *) &terminal_class, JS::NullPtr(), JS::NullPtr());
|
obj = JS_NewObject(smjs_ctx, (JSClass *) &terminal_class);
|
||||||
|
|
||||||
if (!obj) return NULL;
|
if (!obj) return NULL;
|
||||||
|
|
||||||
@ -190,9 +190,9 @@ terminal_array_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId
|
|||||||
static const JSClass terminal_array_class = {
|
static const JSClass terminal_array_class = {
|
||||||
"terminal_array",
|
"terminal_array",
|
||||||
0,
|
0,
|
||||||
JS_PropertyStub, JS_PropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
terminal_array_get_property, JS_StrictPropertyStub,
|
terminal_array_get_property, JS_StrictPropertyStub,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL
|
nullptr, nullptr, nullptr, nullptr
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Return an SMJS object that scripts can use an array to get terminal
|
/** Return an SMJS object that scripts can use an array to get terminal
|
||||||
@ -203,8 +203,7 @@ smjs_get_terminal_array_object(void)
|
|||||||
assert(smjs_ctx);
|
assert(smjs_ctx);
|
||||||
if_assert_failed return NULL;
|
if_assert_failed return NULL;
|
||||||
|
|
||||||
return JS_NewObject(smjs_ctx, (JSClass *) &terminal_array_class,
|
return JS_NewObject(smjs_ctx, (JSClass *) &terminal_array_class);
|
||||||
JS::NullPtr(), JS::NullPtr());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -27,9 +27,9 @@ static void view_state_finalize(JSFreeOp *op, JSObject *obj);
|
|||||||
static const JSClass view_state_class = {
|
static const JSClass view_state_class = {
|
||||||
"view_state",
|
"view_state",
|
||||||
JSCLASS_HAS_PRIVATE, /* struct view_state * */
|
JSCLASS_HAS_PRIVATE, /* struct view_state * */
|
||||||
JS_PropertyStub, JS_DeletePropertyStub,
|
JS_PropertyStub, nullptr,
|
||||||
view_state_get_property, view_state_set_property,
|
view_state_get_property, view_state_set_property,
|
||||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, view_state_finalize
|
nullptr, nullptr, nullptr, view_state_finalize
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Tinyids of properties. Use negative values to distinguish these
|
/* Tinyids of properties. Use negative values to distinguish these
|
||||||
@ -41,10 +41,80 @@ enum view_state_prop {
|
|||||||
VIEW_STATE_URI = -2,
|
VIEW_STATE_URI = -2,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static bool
|
||||||
|
view_state_get_property_plain(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
|
{
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
|
struct view_state *vs;
|
||||||
|
|
||||||
|
/* This can be called if @obj if not itself an instance of the
|
||||||
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
|
* such calls. */
|
||||||
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &view_state_class, NULL))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
vs = JS_GetInstancePrivate(ctx, hobj,
|
||||||
|
(JSClass *) &view_state_class, NULL);
|
||||||
|
if (!vs) return false;
|
||||||
|
|
||||||
|
args.rval().setInt32(vs->plain);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
view_state_set_property_plain(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
|
{
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
|
struct view_state *vs;
|
||||||
|
|
||||||
|
if (argc != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/* This can be called if @obj if not itself an instance of the
|
||||||
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
|
* such calls. */
|
||||||
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &view_state_class, NULL))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
vs = JS_GetInstancePrivate(ctx, hobj,
|
||||||
|
(JSClass *) &view_state_class, NULL);
|
||||||
|
if (!vs) return false;
|
||||||
|
|
||||||
|
vs->plain = args[0].toInt32();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
view_state_get_property_uri(JSContext *ctx, unsigned int argc, jsval *vp)
|
||||||
|
{
|
||||||
|
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||||
|
|
||||||
|
/* This can be called if @obj if not itself an instance of the
|
||||||
|
* appropriate class but has one in its prototype chain. Fail
|
||||||
|
* such calls. */
|
||||||
|
if (!JS_InstanceOf(ctx, hobj, (JSClass *) &view_state_class, NULL))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
struct view_state *vs = JS_GetInstancePrivate(ctx, hobj,
|
||||||
|
(JSClass *) &view_state_class, NULL);
|
||||||
|
if (!vs) return false;
|
||||||
|
|
||||||
|
args.rval().setString(JS_NewStringCopyZ(ctx, struri(vs->uri)));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static const JSPropertySpec view_state_props[] = {
|
static const JSPropertySpec view_state_props[] = {
|
||||||
{ "plain", (unsigned char)VIEW_STATE_PLAIN, JSPROP_ENUMERATE },
|
JS_PSGS("plain", view_state_get_property_plain, view_state_set_property_plain, JSPROP_ENUMERATE),
|
||||||
{ "uri", (unsigned char)VIEW_STATE_URI, JSPROP_ENUMERATE | JSPROP_READONLY },
|
JS_PSG("uri", view_state_get_property_uri, JSPROP_ENUMERATE),
|
||||||
{ NULL }
|
JS_PS_END
|
||||||
};
|
};
|
||||||
|
|
||||||
/* @view_state_class.getProperty */
|
/* @view_state_class.getProperty */
|
||||||
@ -165,8 +235,7 @@ smjs_get_view_state_object(struct view_state *vs)
|
|||||||
if_assert_failed return NULL;
|
if_assert_failed return NULL;
|
||||||
|
|
||||||
view_state_object = JS_NewObject(smjs_ctx,
|
view_state_object = JS_NewObject(smjs_ctx,
|
||||||
(JSClass *) &view_state_class,
|
(JSClass *) &view_state_class);
|
||||||
JS::NullPtr(), JS::NullPtr());
|
|
||||||
|
|
||||||
if (!view_state_object) return NULL;
|
if (!view_state_object) return NULL;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user