rm fns
This commit is contained in:
185
source/quickjs.c
185
source/quickjs.c
@@ -29592,72 +29592,6 @@ static int JS_isConcatSpreadable(JSContext *ctx, JSValueConst obj)
|
||||
return JS_IsArray(ctx, obj);
|
||||
}
|
||||
|
||||
static JSValue js_array_concat(JSContext *ctx, JSValueConst this_val,
|
||||
int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue obj, arr, val;
|
||||
JSValueConst e;
|
||||
int64_t len, k, n;
|
||||
int i, res;
|
||||
|
||||
arr = JS_NULL;
|
||||
obj = JS_ToObject(ctx, this_val);
|
||||
if (JS_IsException(obj))
|
||||
goto exception;
|
||||
|
||||
arr = JS_ArraySpeciesCreate(ctx, obj, JS_NewInt32(ctx, 0));
|
||||
if (JS_IsException(arr))
|
||||
goto exception;
|
||||
n = 0;
|
||||
for (i = -1; i < argc; i++) {
|
||||
if (i < 0)
|
||||
e = obj;
|
||||
else
|
||||
e = argv[i];
|
||||
|
||||
res = JS_isConcatSpreadable(ctx, e);
|
||||
if (res < 0)
|
||||
goto exception;
|
||||
if (res) {
|
||||
if (js_get_length64(ctx, &len, e))
|
||||
goto exception;
|
||||
if (n + len > MAX_SAFE_INTEGER) {
|
||||
JS_ThrowTypeError(ctx, "Array loo long");
|
||||
goto exception;
|
||||
}
|
||||
for (k = 0; k < len; k++, n++) {
|
||||
res = JS_TryGetPropertyInt64(ctx, e, k, &val);
|
||||
if (res < 0)
|
||||
goto exception;
|
||||
if (res) {
|
||||
if (JS_DefinePropertyValueInt64(ctx, arr, n, val,
|
||||
JS_PROP_C_W_E | JS_PROP_THROW) < 0)
|
||||
goto exception;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (n >= MAX_SAFE_INTEGER) {
|
||||
JS_ThrowTypeError(ctx, "Array loo long");
|
||||
goto exception;
|
||||
}
|
||||
if (JS_DefinePropertyValueInt64(ctx, arr, n, JS_DupValue(ctx, e),
|
||||
JS_PROP_C_W_E | JS_PROP_THROW) < 0)
|
||||
goto exception;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
if (JS_SetProperty(ctx, arr, JS_ATOM_length, JS_NewInt64(ctx, n)) < 0)
|
||||
goto exception;
|
||||
|
||||
JS_FreeValue(ctx, obj);
|
||||
return arr;
|
||||
|
||||
exception:
|
||||
JS_FreeValue(ctx, arr);
|
||||
JS_FreeValue(ctx, obj);
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
|
||||
static JSValue js_array_includes(JSContext *ctx, JSValueConst this_val,
|
||||
int argc, JSValueConst *argv)
|
||||
{
|
||||
@@ -29990,50 +29924,6 @@ fail:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static JSValue js_array_flatten(JSContext *ctx, JSValueConst this_val,
|
||||
int argc, JSValueConst *argv, int map)
|
||||
{
|
||||
JSValue obj, arr;
|
||||
JSValueConst mapperFunction, thisArg;
|
||||
int64_t sourceLen;
|
||||
int depthNum;
|
||||
|
||||
arr = JS_NULL;
|
||||
obj = JS_ToObject(ctx, this_val);
|
||||
if (js_get_length64(ctx, &sourceLen, obj))
|
||||
goto exception;
|
||||
|
||||
depthNum = 1;
|
||||
mapperFunction = JS_NULL;
|
||||
thisArg = JS_NULL;
|
||||
if (map) {
|
||||
mapperFunction = argv[0];
|
||||
if (argc > 1) {
|
||||
thisArg = argv[1];
|
||||
}
|
||||
if (check_function(ctx, mapperFunction))
|
||||
goto exception;
|
||||
} else {
|
||||
if (argc > 0 && !JS_IsNull(argv[0])) {
|
||||
if (JS_ToInt32Sat(ctx, &depthNum, argv[0]) < 0)
|
||||
goto exception;
|
||||
}
|
||||
}
|
||||
arr = JS_ArraySpeciesCreate(ctx, obj, JS_NewInt32(ctx, 0));
|
||||
if (JS_IsException(arr))
|
||||
goto exception;
|
||||
if (JS_FlattenIntoArray(ctx, arr, obj, sourceLen, 0, depthNum,
|
||||
mapperFunction, thisArg) < 0)
|
||||
goto exception;
|
||||
JS_FreeValue(ctx, obj);
|
||||
return arr;
|
||||
|
||||
exception:
|
||||
JS_FreeValue(ctx, obj);
|
||||
JS_FreeValue(ctx, arr);
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
|
||||
typedef struct JSArrayIteratorData {
|
||||
JSValue obj;
|
||||
JSIteratorKindEnum kind;
|
||||
@@ -30177,7 +30067,6 @@ static const JSCFunctionListEntry js_iterator_proto_funcs[] = {
|
||||
};
|
||||
|
||||
static const JSCFunctionListEntry js_array_proto_funcs[] = {
|
||||
JS_CFUNC_DEF("concat", 1, js_array_concat ),
|
||||
JS_CFUNC_DEF("toString", 0, js_array_toString ),
|
||||
JS_CFUNC_MAGIC_DEF("pop", 0, js_array_pop, 0 ),
|
||||
JS_CFUNC_MAGIC_DEF("push", 1, js_array_push, 0 ),
|
||||
@@ -30185,8 +30074,6 @@ static const JSCFunctionListEntry js_array_proto_funcs[] = {
|
||||
JS_CFUNC_MAGIC_DEF("unshift", 1, js_array_push, 1 ),
|
||||
JS_CFUNC_MAGIC_DEF("slice", 2, js_array_slice, 0 ),
|
||||
JS_CFUNC_MAGIC_DEF("splice", 2, js_array_slice, 1 ),
|
||||
JS_CFUNC_MAGIC_DEF("flatMap", 1, js_array_flatten, 1 ),
|
||||
JS_CFUNC_MAGIC_DEF("flat", 0, js_array_flatten, 0 ),
|
||||
JS_CFUNC_MAGIC_DEF("values", 0, js_create_array_iterator, JS_ITERATOR_KIND_VALUE ),
|
||||
JS_ALIAS_DEF("[Symbol.iterator]", "values" ),
|
||||
JS_CFUNC_MAGIC_DEF("keys", 0, js_create_array_iterator, JS_ITERATOR_KIND_KEY ),
|
||||
@@ -30336,24 +30223,6 @@ static JSValue js_thisStringValue(JSContext *ctx, JSValueConst this_val)
|
||||
return JS_ThrowTypeError(ctx, "not a string");
|
||||
}
|
||||
|
||||
static JSValue js_string_concat(JSContext *ctx, JSValueConst this_val,
|
||||
int argc, JSValueConst *argv)
|
||||
{
|
||||
JSValue r;
|
||||
int i;
|
||||
|
||||
/* XXX: Use more efficient method */
|
||||
/* XXX: This method is OK if r has a single refcount */
|
||||
/* XXX: should use string_buffer? */
|
||||
r = JS_ToStringCheckObject(ctx, this_val);
|
||||
for (i = 0; i < argc; i++) {
|
||||
if (JS_IsException(r))
|
||||
break;
|
||||
r = JS_ConcatString(ctx, r, JS_DupValue(ctx, argv[i]));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
static int string_cmp(JSString *p1, JSString *p2, int x1, int x2, int len)
|
||||
{
|
||||
int i, c1, c2;
|
||||
@@ -30801,59 +30670,6 @@ exception:
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
|
||||
/* return 0 if before the first char */
|
||||
static int string_prevc(JSString *p, int *pidx)
|
||||
{
|
||||
int idx, c, c1;
|
||||
|
||||
idx = *pidx;
|
||||
if (idx <= 0)
|
||||
return 0;
|
||||
idx--;
|
||||
if (p->is_wide_char) {
|
||||
c = p->u.str16[idx];
|
||||
if (is_lo_surrogate(c) && idx > 0) {
|
||||
c1 = p->u.str16[idx - 1];
|
||||
if (is_hi_surrogate(c1)) {
|
||||
c = from_surrogate(c1, c);
|
||||
idx--;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
c = p->u.str8[idx];
|
||||
}
|
||||
*pidx = idx;
|
||||
return c;
|
||||
}
|
||||
|
||||
static BOOL test_final_sigma(JSString *p, int sigma_pos)
|
||||
{
|
||||
int k, c1;
|
||||
|
||||
/* before C: skip case ignorable chars and check there is
|
||||
a cased letter */
|
||||
k = sigma_pos;
|
||||
for(;;) {
|
||||
c1 = string_prevc(p, &k);
|
||||
if (!lre_is_case_ignorable(c1))
|
||||
break;
|
||||
}
|
||||
if (!lre_is_cased(c1))
|
||||
return FALSE;
|
||||
|
||||
/* after C: skip case ignorable chars and check there is
|
||||
no cased letter */
|
||||
k = sigma_pos + 1;
|
||||
for(;;) {
|
||||
if (k >= p->len)
|
||||
return TRUE;
|
||||
c1 = string_getc(p, &k);
|
||||
if (!lre_is_case_ignorable(c1))
|
||||
break;
|
||||
}
|
||||
return !lre_is_cased(c1);
|
||||
}
|
||||
|
||||
/* also used for String.prototype.valueOf */
|
||||
static JSValue js_string_toString(JSContext *ctx, JSValueConst this_val,
|
||||
int argc, JSValueConst *argv)
|
||||
@@ -30901,7 +30717,6 @@ static JSValue js_string_iterator_next(JSContext *ctx, JSValueConst this_val,
|
||||
|
||||
static const JSCFunctionListEntry js_string_proto_funcs[] = {
|
||||
JS_PROP_INT32_DEF("length", 0, JS_PROP_CONFIGURABLE ),
|
||||
JS_CFUNC_DEF("concat", 1, js_string_concat ),
|
||||
JS_CFUNC_MAGIC_DEF("indexOf", 1, js_string_indexOf, 0 ),
|
||||
JS_CFUNC_MAGIC_DEF("lastIndexOf", 1, js_string_indexOf, 1 ),
|
||||
JS_CFUNC_MAGIC_DEF("match", 1, js_string_match, JS_ATOM_Symbol_match ),
|
||||
|
||||
Reference in New Issue
Block a user