Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file handler.ml
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677open!Core_kernelopen!Js_of_ocamltypet=Js.Unsafe.anyletof_any_exnt~name=letjavascript_strict_equal=phys_equalinifnot(javascript_strict_equal(Js.typeoft)(Js.string"function"))thenraise_s[%message"handler for"name"is not a function"];t;;letsexp_of_t_=Sexp.Atom"<handler>"letthrowing_proxy=letthrowing_functionmissing_field_path=letmissing_field_path=Js.to_stringmissing_field_pathinraise_s[%message(missing_field_path:string)"The field was read on a fake DOM event. You probably called \
[Handler.trigger] in a test, and the handler accessed a field of the event \
that was not provided to [~extra_fields]."]inletcreate_proxy:Js.Unsafe.any->Js.Unsafe.any->Js.Unsafe.any->Js.Unsafe.any=(* Given a base-object, a function that raises an ocaml exception,
and an optional "path" to the base-object, return a proxy object
that behaves exactly like a read-only [base], but any accesses into
that object which aren't present instead call [raise_missing_field_path]
instead of returning [undefined]. The objects returned via successful
indexes into [base] are also wrapped in a proxy of the same design.
Because these proxies yield more proxies, the [path] parameter keeps track
of the field names that were accessed in order to get to the current proxy.
This enhances the error message that is thrown back to OCaml. *)Js.Unsafe.pure_js_expr{js|
(function create_proxy (base, raise_missing_field_path, path) {
path = path || [];
function get(obj, field) {
if (field in obj) {
var field_value = obj[field];
if (typeof field_value === 'object') {
return create_proxy(obj[field], raise_missing_field_path, path.concat([field]));
} else {
return field_value;
}
} else {
var missing_field_path = path.concat([field]).join('.');
raise_missing_field_path(missing_field_path);
}
};
function thrower(_obj, field) {
var missing_field_path = path.concat([field]).join('.');
raise_missing_field_path(missing_field_path);
};
return new Proxy(base, {
get: get,
set: thrower,
deleteProperty: thrower,
enumerate: thrower,
ownKeys: thrower,
has: thrower,
defineProperty: thrower,
getOwnPropertyDescriptor: thrower});
})|js}infunbase->letbase=base|>List.to_array|>Js.Unsafe.obj|>Js.Unsafe.injectinletthrowing_function=throwing_function|>Js.wrap_callback|>Js.Unsafe.injectinletpath=Js.Unsafe.injectJs.nullincreate_proxybasethrowing_functionpath;;lettrigger?(extra_fields=[])t=Js.Unsafe.fun_callt[|throwing_proxyextra_fields|];;