def _wrap_handle(space, handle): """Helper function to wrap a handle into an appropriate app-level object. This function does some basic type dispatching to return a wrapped instance of the appropriate W_Value subclass for the given handle. """ if handle == support.EMJS_ERROR: _raise_error(space) if handle == support.EMJS_UNDEFINED: return space.wrap(undefined) if handle == support.EMJS_NULL: return space.wrap(null) if handle == support.EMJS_FALSE: return space.wrap(false) if handle == support.EMJS_TRUE: return space.wrap(true) typ = support.emjs_typeof(handle) if typ == support.EMJS_TYPE_ERROR: _raise_error(space) if typ == support.EMJS_TYPE_NUMBER: return space.wrap(W_Number(handle)) if typ == support.EMJS_TYPE_STRING: return space.wrap(W_String(handle)) if typ == support.EMJS_TYPE_FUNCTION: return space.wrap(W_Function(handle)) assert typ == support.EMJS_TYPE_OBJECT h_array = getstate(space).h_array if support.emjs_op_instanceof(handle, h_array): return space.wrap(W_Array(handle)) return space.wrap(W_Object(handle))
def instanceof(space, w_lhs, w_rhs): with _unwrap_handle(space, w_lhs) as h_lhs: with _unwrap_handle(space, w_rhs) as h_rhs: res = support.emjs_op_instanceof(h_lhs, h_rhs) _check_error(space, res) return space.newbool(bool(res))