Compare commits
3 Commits
b60e79ccad
...
7468e7e0b9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7468e7e0b9 | ||
|
|
4cf0ce00de | ||
|
|
0714017547 |
@@ -134,7 +134,6 @@ DEF( put_array_el, 1, 3, 0, none)
|
||||
DEF( define_field, 5, 2, 1, atom)
|
||||
DEF( set_name, 5, 1, 1, atom)
|
||||
DEF(set_name_computed, 1, 2, 2, none)
|
||||
DEF( set_proto, 1, 2, 1, none)
|
||||
DEF(define_array_el, 1, 3, 2, none)
|
||||
DEF(copy_data_properties, 2, 3, 3, u8)
|
||||
DEF( define_method, 6, 2, 1, atom_u8)
|
||||
|
||||
878
source/quickjs.c
878
source/quickjs.c
File diff suppressed because it is too large
Load Diff
@@ -639,7 +639,7 @@ JSValue JS_NewObject(JSContext *ctx);
|
||||
|
||||
JSValue JS_NewArray(JSContext *ctx);
|
||||
JSValue JS_NewArrayLen(JSContext *ctx, uint32_t len);
|
||||
JSValue JS_ArrayPush(JSContext *ctx, JSValueConst obj, JSValueConst val);
|
||||
int JS_ArrayPush(JSContext *ctx, JSValueConst obj, JSValueConst val);
|
||||
JSValue JS_ArrayPop(JSContext *ctx, JSValueConst obj);
|
||||
|
||||
JSValue JS_GetPropertyInternal(JSContext *ctx, JSValueConst obj,
|
||||
|
||||
116
tests/suite.cm
116
tests/suite.cm
@@ -1000,9 +1000,6 @@ return {
|
||||
var a = {}
|
||||
var b = meme(a)
|
||||
if (!is_proto(b, a)) throw "is_proto failed on meme"
|
||||
|
||||
var c = Error()
|
||||
if (!is_proto(c, Error)) throw "is_proto failed new"
|
||||
},
|
||||
|
||||
// ============================================================================
|
||||
@@ -1122,11 +1119,11 @@ return {
|
||||
if (!caught) throw "stone object should prevent modification"
|
||||
},
|
||||
|
||||
test_stone_p_frozen: function() {
|
||||
test_is_stone_frozen: function() {
|
||||
var obj = {x: 10}
|
||||
if (stone.p(obj)) throw "stone.p should return false before freezing"
|
||||
if (is_stone(obj)) throw "stone.p should return false before freezing"
|
||||
stone(obj)
|
||||
if (!stone.p(obj)) throw "stone.p should return true after freezing"
|
||||
if (!is_stone(obj)) throw "stone.p should return true after freezing"
|
||||
},
|
||||
|
||||
test_stone_array: function() {
|
||||
@@ -1429,13 +1426,6 @@ return {
|
||||
if ("c" in obj) throw "in operator for non-existing property failed"
|
||||
},
|
||||
|
||||
test_in_operator_array: function() {
|
||||
var arr = [10, 20, 30]
|
||||
if (!(0 in arr)) throw "in operator for array index 0 failed"
|
||||
if (!(2 in arr)) throw "in operator for array index 2 failed"
|
||||
if (3 in arr) throw "in operator for out of bounds index failed"
|
||||
},
|
||||
|
||||
test_in_operator_prototype: function() {
|
||||
var parent = {x: 10}
|
||||
var child = meme(parent)
|
||||
@@ -1483,9 +1473,24 @@ return {
|
||||
},
|
||||
|
||||
test_array_join: function() {
|
||||
var arr = [1, 2, 3]
|
||||
var arr = ["a", "b", "c"]
|
||||
var str = text(arr, ",")
|
||||
if (str != "1,2,3") throw "array join with text() failed"
|
||||
if (str != "a,b,c") throw "array join with text() failed"
|
||||
},
|
||||
|
||||
test_text_array_join_numbers_throw: function() {
|
||||
var caught = false
|
||||
try {
|
||||
text([1, 2, 3], ",")
|
||||
} catch (e) {
|
||||
caught = true
|
||||
}
|
||||
if (!caught) throw "text([numbers], sep) should throw (no implicit coercion)"
|
||||
},
|
||||
|
||||
test_text_array_join_numbers_explicit: function() {
|
||||
var arr = array([1, 2, 3], x => text(x))
|
||||
if (text(arr, ",") != "1,2,3") throw "explicit numeric join failed"
|
||||
},
|
||||
|
||||
// ============================================================================
|
||||
@@ -1519,11 +1524,6 @@ return {
|
||||
if (search(str, "xyz") != null) throw "string search not found failed"
|
||||
},
|
||||
|
||||
test_string_lastIndexOf: function() {
|
||||
var str = "hello hello"
|
||||
if (search(str, "hello", 0, true) != 6) throw "string lastSearch failed"
|
||||
},
|
||||
|
||||
test_string_toLowerCase: function() {
|
||||
var str = "HELLO"
|
||||
if (lower(str) != "hello") throw "string toLowerCase failed"
|
||||
@@ -1541,12 +1541,6 @@ return {
|
||||
if (parts[1] != "b") throw "string split values failed"
|
||||
},
|
||||
|
||||
test_string_match: function() {
|
||||
var str = "hello123"
|
||||
var hasNumbers = /\d/.test(str)
|
||||
if (!hasNumbers) throw "string match with regex failed"
|
||||
},
|
||||
|
||||
null_access: function() {
|
||||
var val = {}
|
||||
var nn = val.a
|
||||
@@ -1654,12 +1648,6 @@ return {
|
||||
if (outer[k1][k2] != "nested") throw "nested object keys failed"
|
||||
},
|
||||
|
||||
test_array_number_key: function() {
|
||||
var a = []
|
||||
a[1] = 1
|
||||
if (a[1] != 1) throw "array should be able to use number as key"
|
||||
},
|
||||
|
||||
test_array_for: function() {
|
||||
var a = [1,2,3]
|
||||
arrfor(a, (x,i) => {
|
||||
@@ -1840,13 +1828,8 @@ return {
|
||||
|
||||
test_function_property_get_throws: function() {
|
||||
var fn = function(a, b) { return a + b }
|
||||
var caught = false
|
||||
try {
|
||||
var x = length(fn)
|
||||
} catch (e) {
|
||||
caught = true
|
||||
}
|
||||
if (!caught) throw "getting property on function should throw"
|
||||
var arity = length(fn)
|
||||
if (arity != 2) throw "length of function should return its arity"
|
||||
},
|
||||
|
||||
test_function_property_set_throws: function() {
|
||||
@@ -2156,15 +2139,6 @@ return {
|
||||
if (result != "abc") throw "reduce string concat failed"
|
||||
},
|
||||
|
||||
test_reduce_to_object: function() {
|
||||
var arr = ["a", "b", "c"]
|
||||
var result = reduce(arr, (obj, val, i) => {
|
||||
obj[val] = i
|
||||
return obj
|
||||
}, {})
|
||||
if (result.a != 0 || result.b != 1 || result.c != 2) throw "reduce to object failed"
|
||||
},
|
||||
|
||||
// ============================================================================
|
||||
// SORT FUNCTION
|
||||
// ============================================================================
|
||||
@@ -2832,11 +2806,6 @@ return {
|
||||
if (search(result, "3.14") != 0) throw "text number float failed"
|
||||
},
|
||||
|
||||
test_text_array_join: function() {
|
||||
var result = text([1, 2, 3], ",")
|
||||
if (result != "1,2,3") throw "text array join failed"
|
||||
},
|
||||
|
||||
test_text_array_join_empty_sep: function() {
|
||||
var result = text(["a", "b", "c"], "")
|
||||
if (result != "abc") throw "text array join empty sep failed"
|
||||
@@ -3123,30 +3092,6 @@ return {
|
||||
// STONE FUNCTION (Additional Tests)
|
||||
// ============================================================================
|
||||
|
||||
test_stone_nested_object: function() {
|
||||
var obj = {inner: {value: 42}}
|
||||
stone(obj)
|
||||
var caught = false
|
||||
try {
|
||||
obj.inner.value = 99
|
||||
} catch (e) {
|
||||
caught = true
|
||||
}
|
||||
if (!caught) throw "stone should freeze nested objects"
|
||||
},
|
||||
|
||||
test_stone_nested_array: function() {
|
||||
var obj = {arr: [1, 2, 3]}
|
||||
stone(obj)
|
||||
var caught = false
|
||||
try {
|
||||
obj.arr[0] = 99
|
||||
} catch (e) {
|
||||
caught = true
|
||||
}
|
||||
if (!caught) throw "stone should freeze nested arrays"
|
||||
},
|
||||
|
||||
test_stone_returns_value: function() {
|
||||
var obj = {x: 1}
|
||||
var result = stone(obj)
|
||||
@@ -3157,7 +3102,7 @@ return {
|
||||
var obj = {x: 1}
|
||||
stone(obj)
|
||||
stone(obj)
|
||||
if (!stone.p(obj)) throw "stone should be idempotent"
|
||||
if (!is_stone(obj)) throw "stone should be idempotent"
|
||||
},
|
||||
|
||||
// ============================================================================
|
||||
@@ -3220,9 +3165,13 @@ return {
|
||||
|
||||
test_delete_array_element: function() {
|
||||
var arr = [1, 2, 3]
|
||||
delete arr[1]
|
||||
if (arr[1] != null) throw "delete array element should set to null"
|
||||
if (length(arr) != 3) throw "delete array element should not change length"
|
||||
var caught = false
|
||||
try {
|
||||
delete arr[1]
|
||||
} catch (e) {
|
||||
caught = true
|
||||
}
|
||||
if (!caught) throw "delete on array element should throw"
|
||||
},
|
||||
|
||||
test_delete_nonexistent: function() {
|
||||
@@ -3281,11 +3230,6 @@ return {
|
||||
if (e.message != "test message") throw "Error creation failed"
|
||||
},
|
||||
|
||||
test_error_is_proto: function() {
|
||||
var e = Error("test")
|
||||
if (!is_proto(e, Error)) throw "Error is_proto failed"
|
||||
},
|
||||
|
||||
test_throw_error_object: function() {
|
||||
var caught = null
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user