rm spreads and iterators
This commit is contained in:
@@ -788,20 +788,22 @@ $_.clock(_ => {
|
||||
var file_info = shop.file_info ? shop.file_info(locator.path) : null
|
||||
var inject = shop.script_inject_for ? shop.script_inject_for(file_info) : []
|
||||
|
||||
// Build values array for injection
|
||||
var vals = array(inject, key => {
|
||||
if (key && key[0] == '$') key = text(key,1)
|
||||
if (key == 'fd') return fd
|
||||
return $_[key]
|
||||
})
|
||||
// Build env object for injection
|
||||
var env = {}
|
||||
for (var i = 0; i < length(inject); i++) {
|
||||
var key = inject[i]
|
||||
if (key && key[0] == '$') key = text(key, 1)
|
||||
if (key == 'fd') env[key] = fd
|
||||
else env[key] = $_[key]
|
||||
}
|
||||
|
||||
// Create use function bound to the program's package
|
||||
var pkg = file_info ? file_info.package : null
|
||||
var use_fn = function(path) { return shop.use(path, pkg) }
|
||||
|
||||
// Call with signature: setup_module(args, use, ..capabilities)
|
||||
// The script wrapper builds $_ from the injected capabilities for backward compatibility
|
||||
var val = call(locator.symbol, null, _cell.args.arg, use_fn, ...vals)
|
||||
// Call with signature: setup_module(args, use, env)
|
||||
// The script wrapper binds $delay, $start, etc. from env
|
||||
var val = call(locator.symbol, null, _cell.args.arg, use_fn, env)
|
||||
|
||||
if (val)
|
||||
throw Error('Program must not return anything');
|
||||
|
||||
@@ -376,17 +376,25 @@ Shop.get_script_capabilities = function(path) {
|
||||
return Shop.script_inject_for(file_info)
|
||||
}
|
||||
|
||||
function inject_params(inject) {
|
||||
if (!inject || !length(inject)) return ''
|
||||
return ', ' + text(inject, ', ')
|
||||
function inject_env(inject) {
|
||||
var env = {}
|
||||
for (var i = 0; i < length(inject); i++) {
|
||||
var inj = inject[i]
|
||||
var key = trim(inj, '$')
|
||||
if (key == 'fd') env[key] = fd
|
||||
else env[key] = my$_[key]
|
||||
}
|
||||
return env
|
||||
}
|
||||
|
||||
function inject_values(inject) {
|
||||
return array(inject, function(inj) {
|
||||
function inject_bindings_code(inject) {
|
||||
var lines = []
|
||||
for (var i = 0; i < length(inject); i++) {
|
||||
var inj = inject[i]
|
||||
var key = trim(inj, '$')
|
||||
if (key == 'fd') return fd
|
||||
return my$_[key]
|
||||
})
|
||||
lines.push(`var $${key} = env["${key}"];`)
|
||||
}
|
||||
return text(lines, '\n')
|
||||
}
|
||||
|
||||
// Build the use function for a specific package context
|
||||
@@ -397,9 +405,14 @@ function make_use_fn_code(pkg_arg) {
|
||||
// for script forms, path is the canonical path of the module
|
||||
var script_form = function(path, script, pkg, inject) {
|
||||
var pkg_arg = pkg ? `'${pkg}'` : 'null'
|
||||
var params = inject_params(inject)
|
||||
|
||||
var fn = `(function setup_module(args, use${params}){ def arg = args; def PACKAGE = ${pkg_arg}; ${script}})`
|
||||
var binds = inject_bindings_code(inject)
|
||||
|
||||
var fn = `(function setup_module(args, use, env){
|
||||
def arg = args;
|
||||
def PACKAGE = ${pkg_arg};
|
||||
${binds}
|
||||
${script}
|
||||
})`
|
||||
return fn
|
||||
}
|
||||
|
||||
@@ -791,13 +804,13 @@ function execute_module(info)
|
||||
// Get file info to determine inject list
|
||||
var file_info = Shop.file_info(mod_resolve.path)
|
||||
var inject = Shop.script_inject_for(file_info)
|
||||
var vals = inject_values(inject)
|
||||
var env = inject_env(inject)
|
||||
var pkg = file_info.package
|
||||
var use_fn = make_use_fn(pkg)
|
||||
|
||||
// Call with signature: setup_module(args, use, ..capabilities)
|
||||
// Call with signature: setup_module(args, use, env)
|
||||
// args is null for module loading
|
||||
used = call(mod_resolve.symbol, context, null, use_fn, ...vals)
|
||||
used = call(mod_resolve.symbol, context, null, use_fn, env)
|
||||
} else if (c_resolve.scope < 900) {
|
||||
// C only
|
||||
used = call_c_module(c_resolve)
|
||||
|
||||
@@ -138,7 +138,6 @@ 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( append, 1, 3, 2, none) /* append enumerated object, update length */
|
||||
DEF(copy_data_properties, 2, 3, 3, u8)
|
||||
DEF( define_method, 6, 2, 1, atom_u8)
|
||||
DEF(define_method_computed, 2, 3, 1, u8) /* must come after define_method */
|
||||
@@ -181,14 +180,7 @@ DEF(make_var_ref_ref, 7, 0, 2, atom_u16)
|
||||
DEF( make_var_ref, 5, 0, 2, atom)
|
||||
|
||||
DEF( for_in_start, 1, 1, 1, none)
|
||||
DEF( for_of_start, 1, 1, 3, none)
|
||||
DEF( for_in_next, 1, 1, 3, none)
|
||||
DEF( for_of_next, 2, 3, 5, u8)
|
||||
DEF(iterator_check_object, 1, 1, 1, none)
|
||||
DEF(iterator_get_value_done, 1, 2, 3, none) /* catch_offset obj -> catch_offset value done */
|
||||
DEF( iterator_close, 1, 3, 0, none)
|
||||
DEF( iterator_next, 1, 4, 4, none)
|
||||
DEF( iterator_call, 2, 4, 5, u8)
|
||||
|
||||
/* arithmetic/logic operations */
|
||||
DEF( neg, 1, 1, 1, none)
|
||||
|
||||
1959
source/quickjs.c
1959
source/quickjs.c
File diff suppressed because it is too large
Load Diff
@@ -3359,38 +3359,6 @@ return {
|
||||
if (!caught || caught.message != "my error") throw "throw Error object failed"
|
||||
},
|
||||
|
||||
// ============================================================================
|
||||
// REGEX TESTS
|
||||
// ============================================================================
|
||||
|
||||
test_regex_test: function() {
|
||||
var re = /hello/
|
||||
if (!re.test("hello world")) throw "regex test match failed"
|
||||
if (re.test("goodbye world")) throw "regex test no match failed"
|
||||
},
|
||||
|
||||
test_regex_test_case_sensitive: function() {
|
||||
var re = /hello/
|
||||
if (re.test("HELLO")) throw "regex should be case sensitive by default"
|
||||
},
|
||||
|
||||
test_regex_test_case_insensitive: function() {
|
||||
var re = /hello/i
|
||||
if (!re.test("HELLO")) throw "regex case insensitive failed"
|
||||
},
|
||||
|
||||
test_regex_digit: function() {
|
||||
var re = /\d+/
|
||||
if (!re.test("abc123")) throw "regex digit failed"
|
||||
if (re.test("abc")) throw "regex digit no match failed"
|
||||
},
|
||||
|
||||
test_regex_word_boundary: function() {
|
||||
var re = /\bword\b/
|
||||
if (!re.test("a word here")) throw "regex word boundary failed"
|
||||
if (re.test("awordhere")) throw "regex word boundary no match failed"
|
||||
},
|
||||
|
||||
// ============================================================================
|
||||
// STRING METHOD EDGE CASES
|
||||
// ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user