rm some more fns
This commit is contained in:
248
source/quickjs.c
248
source/quickjs.c
@@ -909,7 +909,7 @@ static JSValue js_call_bound_function(JSContext *ctx, JSValueConst func_obj,
|
||||
static JSValue JS_CallInternal(JSContext *ctx, JSValueConst func_obj,
|
||||
JSValueConst this_obj, JSValueConst new_target,
|
||||
int argc, JSValue *argv, int flags);
|
||||
static JSValue JS_CallInternal_OLD(JSContext *ctx, JSValueConst func_obj,
|
||||
static JSValue JS_CallInternal(JSContext *ctx, JSValueConst func_obj,
|
||||
JSValueConst this_obj, JSValueConst new_target,
|
||||
int argc, JSValue *argv, int flags);
|
||||
static JSValue JS_CallFree(JSContext *ctx, JSValue func_obj, JSValueConst this_obj,
|
||||
@@ -9122,18 +9122,6 @@ BOOL JS_IsCFunction(JSContext *ctx, JSValueConst val, JSCFunction *func, int mag
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Constructors are no longer a separate concept - treat as functions */
|
||||
BOOL JS_IsConstructor(JSContext *ctx, JSValueConst val)
|
||||
{
|
||||
return JS_IsFunction(ctx, val);
|
||||
}
|
||||
|
||||
/* No-op: constructor bit is no longer used */
|
||||
BOOL JS_SetConstructorBit(JSContext *ctx, JSValueConst func_obj, BOOL val)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL JS_IsError(JSContext *ctx, JSValueConst val)
|
||||
{
|
||||
JSObject *p;
|
||||
@@ -11907,7 +11895,7 @@ static VMExecState vm_execute_frame(JSContext *ctx, struct VMFrame *frame,
|
||||
{
|
||||
/* TODO: Replace with proper bytecode loop extraction */
|
||||
/* For now, delegate to the old recursive implementation */
|
||||
*ret_val = JS_CallInternal_OLD(ctx, frame->cur_func, frame->this_obj,
|
||||
*ret_val = JS_CallInternal(ctx, frame->cur_func, frame->this_obj,
|
||||
frame->new_target, frame->arg_count,
|
||||
vm_frame_get_arg_buf(ctx, frame), 0);
|
||||
if (JS_IsException(*ret_val))
|
||||
@@ -11915,21 +11903,9 @@ static VMExecState vm_execute_frame(JSContext *ctx, struct VMFrame *frame,
|
||||
return VM_EXEC_RETURN;
|
||||
}
|
||||
|
||||
/* Trampoline-based JS_CallInternal - eliminates C stack recursion */
|
||||
static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
|
||||
JSValueConst this_obj, JSValueConst new_target,
|
||||
int argc, JSValue *argv, int flags)
|
||||
{
|
||||
/* TODO: Implement full trampoline */
|
||||
/* For now, just delegate to OLD implementation */
|
||||
return JS_CallInternal_OLD(caller_ctx, func_obj, this_obj, new_target,
|
||||
argc, argv, flags);
|
||||
}
|
||||
|
||||
/* OLD recursive implementation - to be removed after trampoline is complete */
|
||||
static JSValue JS_CallInternal_OLD(JSContext *caller_ctx, JSValueConst func_obj,
|
||||
JSValueConst this_obj, JSValueConst new_target,
|
||||
int argc, JSValue *argv, int flags)
|
||||
{
|
||||
JSRuntime *rt = caller_ctx->rt;
|
||||
JSContext *ctx;
|
||||
@@ -12346,7 +12322,7 @@ static JSValue JS_CallInternal_OLD(JSContext *caller_ctx, JSValueConst func_obj,
|
||||
profile_record_call_site(rt, b, (uint32_t)(pc - b->byte_code_buf));
|
||||
#endif
|
||||
/* TODO: Use trampoline - for now keep recursive */
|
||||
ret_val = JS_CallInternal_OLD(ctx, call_argv[-1], JS_NULL,
|
||||
ret_val = JS_CallInternal(ctx, call_argv[-1], JS_NULL,
|
||||
JS_NULL, call_argc, call_argv, 0);
|
||||
if (unlikely(JS_IsException(ret_val)))
|
||||
goto exception;
|
||||
@@ -12406,12 +12382,12 @@ static JSValue JS_CallInternal_OLD(JSContext *caller_ctx, JSValueConst func_obj,
|
||||
proxy_argv[0] = name; /* still owned by stack; freed by normal cleanup */
|
||||
proxy_argv[1] = args;
|
||||
|
||||
ret_val = JS_CallInternal_OLD(ctx, call_argv[-2], JS_NULL,
|
||||
ret_val = JS_CallInternal(ctx, call_argv[-2], JS_NULL,
|
||||
JS_NULL, 2, proxy_argv, 0);
|
||||
JS_FreeValue(ctx, args);
|
||||
}
|
||||
} else {
|
||||
ret_val = JS_CallInternal_OLD(ctx, call_argv[-1], call_argv[-2],
|
||||
ret_val = JS_CallInternal(ctx, call_argv[-1], call_argv[-2],
|
||||
JS_NULL, call_argc, call_argv, 0);
|
||||
}
|
||||
if (unlikely(JS_IsException(ret_val)))
|
||||
@@ -12475,7 +12451,7 @@ static JSValue JS_CallInternal_OLD(JSContext *caller_ctx, JSValueConst func_obj,
|
||||
proxy_argv[0] = sp[-3]; /* name */
|
||||
proxy_argv[1] = sp[-1]; /* args array already built by bytecode */
|
||||
|
||||
ret_val = JS_CallInternal_OLD(ctx, sp[-2], JS_NULL,
|
||||
ret_val = JS_CallInternal(ctx, sp[-2], JS_NULL,
|
||||
JS_NULL, 2, proxy_argv, 0);
|
||||
} else {
|
||||
ret_val = js_function_apply(ctx, sp[-3], 2, (JSValueConst *)&sp[-2], magic);
|
||||
@@ -12544,7 +12520,7 @@ static JSValue JS_CallInternal_OLD(JSContext *caller_ctx, JSValueConst func_obj,
|
||||
ret_val = JS_EvalObject(ctx, JS_NULL, obj,
|
||||
JS_EVAL_TYPE_DIRECT, scope_idx);
|
||||
} else {
|
||||
ret_val = JS_CallInternal_OLD(ctx, call_argv[-1], JS_NULL,
|
||||
ret_val = JS_CallInternal(ctx, call_argv[-1], JS_NULL,
|
||||
JS_NULL, call_argc, call_argv, 0);
|
||||
}
|
||||
if (unlikely(JS_IsException(ret_val)))
|
||||
@@ -26457,31 +26433,6 @@ static JSValueConst JS_NewGlobalCConstructor(JSContext *ctx, const char *name,
|
||||
return func_obj;
|
||||
}
|
||||
|
||||
static JSValue js_global_eval(JSContext *ctx, JSValueConst this_val,
|
||||
int argc, JSValueConst *argv)
|
||||
{
|
||||
return JS_EvalObject(ctx, ctx->global_obj, argv[0], JS_EVAL_TYPE_INDIRECT, -1);
|
||||
}
|
||||
|
||||
static JSValue js_global_isNaN(JSContext *ctx, JSValueConst this_val,
|
||||
int argc, JSValueConst *argv)
|
||||
{
|
||||
double d;
|
||||
|
||||
if (unlikely(JS_ToFloat64(ctx, &d, argv[0])))
|
||||
return JS_EXCEPTION;
|
||||
return JS_NewBool(ctx, isnan(d));
|
||||
}
|
||||
|
||||
static JSValue js_global_isFinite(JSContext *ctx, JSValueConst this_val,
|
||||
int argc, JSValueConst *argv)
|
||||
{
|
||||
double d;
|
||||
if (unlikely(JS_ToFloat64(ctx, &d, argv[0])))
|
||||
return JS_EXCEPTION;
|
||||
return JS_NewBool(ctx, isfinite(d));
|
||||
}
|
||||
|
||||
/* Object class */
|
||||
|
||||
static JSValue JS_ToObject(JSContext *ctx, JSValueConst val)
|
||||
@@ -26505,162 +26456,6 @@ static JSValue JS_ToObjectFree(JSContext *ctx, JSValue val)
|
||||
return obj;
|
||||
}
|
||||
|
||||
static int js_obj_to_desc(JSContext *ctx, JSPropertyDescriptor *d,
|
||||
JSValueConst desc)
|
||||
{
|
||||
JSValue val, getter, setter;
|
||||
int flags;
|
||||
|
||||
if (!JS_IsObject(desc)) {
|
||||
JS_ThrowTypeErrorNotAnObject(ctx);
|
||||
return -1;
|
||||
}
|
||||
flags = 0;
|
||||
val = JS_NULL;
|
||||
getter = JS_NULL;
|
||||
setter = JS_NULL;
|
||||
if (JS_HasProperty(ctx, desc, JS_ATOM_enumerable)) {
|
||||
JSValue prop = JS_GetProperty(ctx, desc, JS_ATOM_enumerable);
|
||||
if (JS_IsException(prop))
|
||||
goto fail;
|
||||
flags |= JS_PROP_HAS_ENUMERABLE;
|
||||
if (JS_ToBoolFree(ctx, prop))
|
||||
flags |= JS_PROP_ENUMERABLE;
|
||||
}
|
||||
if (JS_HasProperty(ctx, desc, JS_ATOM_configurable)) {
|
||||
JSValue prop = JS_GetProperty(ctx, desc, JS_ATOM_configurable);
|
||||
if (JS_IsException(prop))
|
||||
goto fail;
|
||||
flags |= JS_PROP_HAS_CONFIGURABLE;
|
||||
if (JS_ToBoolFree(ctx, prop))
|
||||
flags |= JS_PROP_CONFIGURABLE;
|
||||
}
|
||||
if (JS_HasProperty(ctx, desc, JS_ATOM_value)) {
|
||||
flags |= JS_PROP_HAS_VALUE;
|
||||
val = JS_GetProperty(ctx, desc, JS_ATOM_value);
|
||||
if (JS_IsException(val))
|
||||
goto fail;
|
||||
}
|
||||
if (JS_HasProperty(ctx, desc, JS_ATOM_writable)) {
|
||||
JSValue prop = JS_GetProperty(ctx, desc, JS_ATOM_writable);
|
||||
if (JS_IsException(prop))
|
||||
goto fail;
|
||||
flags |= JS_PROP_HAS_WRITABLE;
|
||||
if (JS_ToBoolFree(ctx, prop))
|
||||
flags |= JS_PROP_WRITABLE;
|
||||
}
|
||||
if (JS_HasProperty(ctx, desc, JS_ATOM_get)) {
|
||||
flags |= JS_PROP_HAS_GET;
|
||||
getter = JS_GetProperty(ctx, desc, JS_ATOM_get);
|
||||
if (JS_IsException(getter) ||
|
||||
!(JS_IsNull(getter) || JS_IsFunction(ctx, getter))) {
|
||||
JS_ThrowTypeError(ctx, "invalid getter");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
if (JS_HasProperty(ctx, desc, JS_ATOM_set)) {
|
||||
flags |= JS_PROP_HAS_SET;
|
||||
setter = JS_GetProperty(ctx, desc, JS_ATOM_set);
|
||||
if (JS_IsException(setter) ||
|
||||
!(JS_IsNull(setter) || JS_IsFunction(ctx, setter))) {
|
||||
JS_ThrowTypeError(ctx, "invalid setter");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
if ((flags & (JS_PROP_HAS_SET | JS_PROP_HAS_GET)) &&
|
||||
(flags & (JS_PROP_HAS_VALUE | JS_PROP_HAS_WRITABLE))) {
|
||||
JS_ThrowTypeError(ctx, "cannot have setter/getter and value or writable");
|
||||
goto fail;
|
||||
}
|
||||
d->flags = flags;
|
||||
d->value = val;
|
||||
d->getter = getter;
|
||||
d->setter = setter;
|
||||
return 0;
|
||||
fail:
|
||||
JS_FreeValue(ctx, val);
|
||||
JS_FreeValue(ctx, getter);
|
||||
JS_FreeValue(ctx, setter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static __exception int JS_DefinePropertyDesc(JSContext *ctx, JSValueConst obj,
|
||||
JSAtom prop, JSValueConst desc,
|
||||
int flags)
|
||||
{
|
||||
JSPropertyDescriptor d;
|
||||
int ret;
|
||||
|
||||
if (js_obj_to_desc(ctx, &d, desc) < 0)
|
||||
return -1;
|
||||
|
||||
ret = JS_DefineProperty(ctx, obj, prop,
|
||||
d.value, d.getter, d.setter, d.flags | flags);
|
||||
js_free_desc(ctx, &d);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static __exception int JS_ObjectDefineProperties(JSContext *ctx,
|
||||
JSValueConst obj,
|
||||
JSValueConst properties)
|
||||
{
|
||||
JSValue props, desc;
|
||||
JSObject *p;
|
||||
JSPropertyEnum *atoms;
|
||||
uint32_t len, i;
|
||||
int ret = -1;
|
||||
|
||||
if (!JS_IsObject(obj)) {
|
||||
JS_ThrowTypeErrorNotAnObject(ctx);
|
||||
return -1;
|
||||
}
|
||||
desc = JS_NULL;
|
||||
props = JS_ToObject(ctx, properties);
|
||||
if (JS_IsException(props))
|
||||
return -1;
|
||||
p = JS_VALUE_GET_OBJ(props);
|
||||
/* XXX: not done in the same order as the spec */
|
||||
if (JS_GetOwnPropertyNamesInternal(ctx, &atoms, &len, p, JS_GPN_ENUM_ONLY | JS_GPN_STRING_MASK | JS_GPN_SYMBOL_MASK) < 0)
|
||||
goto exception;
|
||||
for(i = 0; i < len; i++) {
|
||||
JS_FreeValue(ctx, desc);
|
||||
desc = JS_GetProperty(ctx, props, atoms[i].atom);
|
||||
if (JS_IsException(desc))
|
||||
goto exception;
|
||||
if (JS_DefinePropertyDesc(ctx, obj, atoms[i].atom, desc, JS_PROP_THROW) < 0)
|
||||
goto exception;
|
||||
}
|
||||
ret = 0;
|
||||
|
||||
exception:
|
||||
JS_FreePropertyEnum(ctx, atoms, len);
|
||||
JS_FreeValue(ctx, props);
|
||||
JS_FreeValue(ctx, desc);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static JSValue js_object_constructor(JSContext *ctx, JSValueConst new_target,
|
||||
int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue ret;
|
||||
if (!JS_IsNull(new_target) &&
|
||||
JS_VALUE_GET_OBJ(new_target) !=
|
||||
JS_VALUE_GET_OBJ(JS_GetActiveFunction(ctx))) {
|
||||
ret = js_create_from_ctor(ctx, new_target, JS_CLASS_OBJECT);
|
||||
} else {
|
||||
int tag = JS_VALUE_GET_NORM_TAG(argv[0]);
|
||||
switch(tag) {
|
||||
case JS_TAG_NULL:
|
||||
ret = JS_NewObject(ctx);
|
||||
break;
|
||||
default:
|
||||
ret = JS_ToObject(ctx, argv[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static JSValue JS_GetOwnPropertyNames2(JSContext *ctx, JSValueConst obj1,
|
||||
int flags, int kind)
|
||||
{
|
||||
@@ -26798,35 +26593,6 @@ static JSValue js_object_seal(JSContext *ctx, JSValueConst this_val,
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
|
||||
static JSValue JS_SpeciesConstructor(JSContext *ctx, JSValueConst obj,
|
||||
JSValueConst defaultConstructor)
|
||||
{
|
||||
JSValue ctor, species;
|
||||
|
||||
if (!JS_IsObject(obj))
|
||||
return JS_ThrowTypeErrorNotAnObject(ctx);
|
||||
ctor = JS_GetProperty(ctx, obj, JS_ATOM_constructor);
|
||||
if (JS_IsException(ctor))
|
||||
return ctor;
|
||||
if (JS_IsNull(ctor))
|
||||
return JS_DupValue(ctx, defaultConstructor);
|
||||
if (!JS_IsObject(ctor)) {
|
||||
JS_FreeValue(ctx, ctor);
|
||||
return JS_ThrowTypeErrorNotAnObject(ctx);
|
||||
}
|
||||
species = JS_GetProperty(ctx, ctor, JS_ATOM_Symbol_species);
|
||||
JS_FreeValue(ctx, ctor);
|
||||
if (JS_IsException(species))
|
||||
return species;
|
||||
if (JS_IsNull(species) || JS_IsNull(species))
|
||||
return JS_DupValue(ctx, defaultConstructor);
|
||||
if (!JS_IsConstructor(ctx, species)) {
|
||||
JS_FreeValue(ctx, species);
|
||||
return JS_ThrowTypeError(ctx, "not a constructor");
|
||||
}
|
||||
return species;
|
||||
}
|
||||
|
||||
/* Function class */
|
||||
|
||||
static JSValue js_function_proto(JSContext *ctx, JSValueConst this_val,
|
||||
|
||||
@@ -86,7 +86,6 @@ enum {
|
||||
JS_TAG_INT = 0,
|
||||
JS_TAG_BOOL = 1,
|
||||
JS_TAG_NULL = 2,
|
||||
// TAG_UNDEFINED
|
||||
JS_TAG_UNINITIALIZED = 4,
|
||||
JS_TAG_CATCH_OFFSET = 5,
|
||||
JS_TAG_EXCEPTION = 6,
|
||||
|
||||
Reference in New Issue
Block a user