def bind(space, w_fn, w_ctx): """Create a copy of a function, bound to the given context.""" func = space.interp_w(W_Function, w_fn) h_bound = support.emjs_dup(func.handle) _check_error(space, h_bound) bound = W_Function(h_bound, w_ctx, func.callback) return space.wrap(bound)
def _gather_callback(dataptr, h_item): iterator = _gather_callback_self.instance if iterator is not None: assert isinstance(iterator, W_AbstractIterator) w_item = _wrap_handle(iterator.space, support.emjs_dup(h_item)) iterator.keys_w.append(w_item) else: os.write(2, "no active iterator\n") raise RuntimeError("no active iterator")
# properly through to the javascript side. # w_jserror = getstate(space).w_jserror # if isinstance(pyerr, w_jserror): # with _unwrap_handle(pyerror.args[0]) as h_err: # support.emjs_set_error(h_err) # else: # h_msg = make_error_string() # h_data = make_error_pickle() # h_err = new(h_pyerror, [h_msg, h_data]) # support.emjs_set_error(h_err) # support.emjs_free(h_err) errmsg = pyerr.errorstr(space) h_errmsg = support.emjs_make_strn(errmsg, len(errmsg)) support.emjs_set_error(h_errmsg) support.emjs_free(h_errmsg) return support.EMJS_ERROR else: # Note that the js-side callback stub frees the result handle, # so we have to dup it here to avoid breaking the w_res object. # XXX TODO: avoid the dup for transiently-unwrapped values. with _unwrap_handle(space, w_res) as h_res: return support.emjs_dup(h_res) # Some useful singleton instances. undefined = W_Undefined(support.EMJS_UNDEFINED) null = W_Object(support.EMJS_NULL) false = W_Boolean(support.EMJS_FALSE) true = W_Boolean(support.EMJS_TRUE)