From b55ef3547ad75892f3ca7f0ee24f4c601787964d Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Sun, 2 Jan 2022 13:17:57 +0100 Subject: [PATCH 1/7] Compiler: cleanup wrap-with-fun option --- compiler/bin-js_of_ocaml/build_fs.ml | 2 +- compiler/bin-js_of_ocaml/cmd_arg.ml | 25 ++++- compiler/bin-js_of_ocaml/cmd_arg.mli | 6 +- compiler/bin-js_of_ocaml/compile.ml | 11 +-- compiler/bin-jsoo_fs/jsoo_fs.ml | 2 +- compiler/lib/driver.ml | 131 ++++++++++++++++----------- compiler/lib/driver.mli | 2 +- 7 files changed, 111 insertions(+), 68 deletions(-) diff --git a/compiler/bin-js_of_ocaml/build_fs.ml b/compiler/bin-js_of_ocaml/build_fs.ml index 807f92cce3..a3b59b797d 100644 --- a/compiler/bin-js_of_ocaml/build_fs.ml +++ b/compiler/bin-js_of_ocaml/build_fs.ml @@ -71,7 +71,7 @@ function jsoo_create_file_extern(name,content){ let pfs_fmt = Pretty_print.to_out_channel chan in Driver.f ~standalone:true - ~global:`globalThis + ~wrap_with_fun:`Iife pfs_fmt (Parse_bytecode.Debug.create ~toplevel:false false) code) diff --git a/compiler/bin-js_of_ocaml/cmd_arg.ml b/compiler/bin-js_of_ocaml/cmd_arg.ml index 0654550f75..c5cd37f34d 100644 --- a/compiler/bin-js_of_ocaml/cmd_arg.ml +++ b/compiler/bin-js_of_ocaml/cmd_arg.ml @@ -33,7 +33,7 @@ type t = ; input_file : string option ; params : (string * string) list ; static_env : (string * string) list - ; wrap_with_fun : string option + ; wrap_with_fun : [ `Iife | `Named of string | `Anonymous ] ; target_env : Target_env.t ; (* toplevel *) dynlink : bool @@ -49,6 +49,25 @@ type t = ; keep_unit_names : bool } +let wrap_with_fun_conv = + let conv s = + if String.equal s "" + then Ok `Anonymous + else if Javascript.is_ident s + then Ok (`Named s) + else Error (`Msg "must be empty or a valid JavaScript identifier") + in + let printer fmt o = + Format.fprintf + fmt + "%s" + (match o with + | `Anonymous -> "" + | `Named s -> s + | `Iife -> "") + in + Arg.conv (conv, printer) + let options = let toplevel_section = "OPTIONS (TOPLEVEL)" in let filesystem_section = "OPTIONS (FILESYSTEM)" in @@ -118,7 +137,7 @@ let options = "Wrap the generated JavaScript code inside a function that needs to be applied \ with the global object." in - Arg.(value & opt (some string) None & info [ "wrap-with-fun" ] ~doc) + Arg.(value & opt wrap_with_fun_conv `Iife & info [ "wrap-with-fun" ] ~doc) in let set_param = let doc = "Set compiler options." in @@ -394,7 +413,7 @@ let options_runtime_only = "Wrap the generated JavaScript code inside a function that needs to be applied \ with the global object." in - Arg.(value & opt (some string) None & info [ "wrap-with-fun" ] ~doc) + Arg.(value & opt wrap_with_fun_conv `Iife & info [ "wrap-with-fun" ] ~doc) in let set_param = let doc = "Set compiler options." in diff --git a/compiler/bin-js_of_ocaml/cmd_arg.mli b/compiler/bin-js_of_ocaml/cmd_arg.mli index d2dc3cd333..d26cbaf5b4 100644 --- a/compiler/bin-js_of_ocaml/cmd_arg.mli +++ b/compiler/bin-js_of_ocaml/cmd_arg.mli @@ -31,7 +31,11 @@ type t = ; input_file : string option ; params : (string * string) list ; static_env : (string * string) list - ; wrap_with_fun : string option + ; wrap_with_fun : + [ `Iife (* IIFE stands for Immediately Invoked Function Expression *) + | `Named of string + | `Anonymous + ] ; target_env : Target_env.t ; (* toplevel *) dynlink : bool diff --git a/compiler/bin-js_of_ocaml/compile.ml b/compiler/bin-js_of_ocaml/compile.ml index c280d3c75a..faf3af8632 100644 --- a/compiler/bin-js_of_ocaml/compile.ml +++ b/compiler/bin-js_of_ocaml/compile.ml @@ -54,11 +54,6 @@ let run } = let dynlink = dynlink || toplevel || runtime_only in let custom_header = common.Jsoo_cmdline.Arg.custom_header in - let global = - match wrap_with_fun with - | Some fun_name -> `Bind_to fun_name - | None -> `globalThis - in Jsoo_cmdline.Arg.eval common; (match output_file with | `Stdout, _ -> () @@ -165,7 +160,7 @@ let run ~standalone ?profile ~linkall - ~global + ~wrap_with_fun ~dynlink ?source_map ?custom_header @@ -192,7 +187,7 @@ let run ~standalone ?profile ~linkall - ~global + ~wrap_with_fun ~dynlink ?source_map ?custom_header @@ -208,7 +203,7 @@ let run ~standalone ?profile ?custom_header - ~global + ~wrap_with_fun pfs_fmt one.debug code))); diff --git a/compiler/bin-jsoo_fs/jsoo_fs.ml b/compiler/bin-jsoo_fs/jsoo_fs.ml index 2f9f8eb4d8..d8c02707bb 100644 --- a/compiler/bin-jsoo_fs/jsoo_fs.ml +++ b/compiler/bin-jsoo_fs/jsoo_fs.ml @@ -98,7 +98,7 @@ function jsoo_create_file_extern(name,content){ let pfs_fmt = Pretty_print.to_out_channel chan in Driver.f ~standalone:true - ~global:`globalThis + ~wrap_with_fun:`Iife pfs_fmt (Parse_bytecode.Debug.create ~toplevel:false false) code) diff --git a/compiler/lib/driver.ml b/compiler/lib/driver.ml index d323c830d0..c3df015dd3 100644 --- a/compiler/lib/driver.ml +++ b/compiler/lib/driver.ml @@ -318,14 +318,14 @@ let coloring js = if times () then Format.eprintf " coloring: %a@." Timer.print t; js -let output formatter ~standalone ~custom_header ?source_map () js = +let output formatter ~standalone ~custom_header ~source_map () js = let t = Timer.make () in if times () then Format.eprintf "Start Writing file...@."; if standalone then header ~custom_header formatter; Js_output.program formatter ?source_map js; if times () then Format.eprintf " write: %a@." Timer.print t -let pack ~global ~standalone { Linker.runtime_code = js; always_required_codes } = +let pack ~wrap_with_fun ~standalone { Linker.runtime_code = js; always_required_codes } = let module J = Javascript in let t = Timer.make () in if times () then Format.eprintf "Start Optimizing js...@."; @@ -349,40 +349,30 @@ let pack ~global ~standalone { Linker.runtime_code = js; always_required_codes } else js in (* pack *) - let use_strict js ~can_use_strict = - if Config.Flag.strictmode () && can_use_strict - then (J.Statement (J.Expression_statement (J.EStr ("use strict", `Utf8))), J.N) :: js - else js - in - let wrap_in_iifa ~can_use_strict js = - let js = + let wrap_in_iife ~use_strict js = + let var ident e = + J.Statement (J.Variable_statement [ J.ident ident, Some (e, J.N) ]), J.N + in + let expr e = J.Statement (J.Expression_statement e), J.N in + let old_global_object_shim js = let o = new Js_traverse.free in let js = o#program js in if StringSet.mem Constant.old_global_object o#get_free_name - then - ( J.Statement - (J.Variable_statement - [ ( J.ident Constant.old_global_object - , Some (J.EVar (J.ident global_object), J.N) ) - ]) - , J.N ) - :: js + then var Constant.old_global_object (J.EVar (J.ident global_object)) :: js else js in - let f = - J.EFun (None, [ J.ident global_object ], use_strict js ~can_use_strict, J.U) + let efun args body = J.EFun (None, args, body, J.U) in + let sfun name args body = J.Function_declaration (name, args, body, J.U), J.U in + let mk f = + let js = old_global_object_shim js in + let js = if use_strict then expr (J.EStr ("use strict", `Utf8)) :: js else js in + f [ J.ident global_object ] js in - let expr = - match global with - | `Function -> f - | `Bind_to _ -> f - | `Custom name -> J.ECall (f, [ J.EVar (J.ident name), `Not_spread ], J.N) - | `globalThis -> J.ECall (f, [ J.EVar (J.ident global_object), `Not_spread ], J.N) - in - match global with - | `Bind_to name -> - [ J.Statement (J.Variable_statement [ J.ident name, Some (expr, J.N) ]), J.N ] - | _ -> [ J.Statement (J.Expression_statement expr), J.N ] + match wrap_with_fun with + | `Anonymous -> expr (mk efun) + | `Named name -> mk (sfun (J.ident name)) + | `Iife -> + expr (J.ECall (mk efun, [ J.EVar (J.ident global_object), `Not_spread ], J.N)) in let always_required_js = (* consider adding a comments in the generated file with original @@ -394,17 +384,19 @@ let pack ~global ~standalone { Linker.runtime_code = js; always_required_codes } List.map always_required_codes ~f:(fun { Linker.program; filename = _; requires = _ } -> - wrap_in_iifa ~can_use_strict:false program) + wrap_in_iife ~use_strict:false program) in - let runtime_js = wrap_in_iifa ~can_use_strict:true js in - let js = List.flatten always_required_js @ runtime_js in + let runtime_js = wrap_in_iife ~use_strict:(Config.Flag.strictmode ()) js in + let js = always_required_js @ [ runtime_js ] in let js = - match global, standalone with - | (`Function | `Bind_to _ | `Custom _), _ -> js - | `globalThis, false -> js - | `globalThis, true -> - let s = - {| + match wrap_with_fun, standalone with + | `Named _, _ -> js + | `Anonymous, _ -> js + | `Iife, false -> js + | `Iife, true -> + let e = + let s = + {| (function (Object) { typeof globalThis !== 'object' && ( this ? @@ -421,10 +413,10 @@ let pack ~global ~standalone { Linker.runtime_code = js; always_required_codes } } }(Object)); |} + in + let lex = Parse_js.Lexer.of_lexbuf (Lexing.from_string s) in + Parse_js.parse lex in - let lex = Lexing.from_string s in - let lex = Parse_js.Lexer.of_lexbuf lex in - let e = Parse_js.parse lex in e @ js in (* post pack optim *) @@ -456,14 +448,14 @@ let configure formatter p = type profile = Code.program -> Code.program -let f - ?(standalone = true) - ?(global = `globalThis) - ?(profile = o1) - ?(dynlink = false) - ?(linkall = false) - ?source_map - ?custom_header +let full + ~standalone + ~wrap_with_fun + ~profile + ~dynlink + ~linkall + ~source_map + ~custom_header formatter d p = @@ -480,10 +472,10 @@ let f let emit = generate d ~exported_runtime +> link ~standalone ~linkall ~export_runtime:dynlink - +> pack ~global ~standalone + +> pack ~wrap_with_fun ~standalone +> coloring +> check_js - +> output formatter ~standalone ~custom_header ?source_map () + +> output formatter ~standalone ~custom_header ~source_map () in if times () then Format.eprintf "Start Optimizing...@."; let t = Timer.make () in @@ -491,9 +483,42 @@ let f let () = if times () then Format.eprintf " optimizations : %a@." Timer.print t in emit r +let f + ?(standalone = true) + ?(wrap_with_fun = `Iife) + ?(profile = o1) + ?(dynlink = false) + ?(linkall = false) + ?source_map + ?custom_header + formatter + d + p = + full + ~standalone + ~wrap_with_fun + ~profile + ~dynlink + ~linkall + ~source_map + ~custom_header + formatter + d + p + let from_string prims s formatter = let p, d = Parse_bytecode.from_string prims s in - f ~standalone:false ~global:`Function formatter d p + full + ~standalone:false + ~wrap_with_fun:`Anonymous + ~profile:o1 + ~dynlink:false + ~linkall:false + ~source_map:None + ~custom_header:None + formatter + d + p let profiles = [ 1, o1; 2, o2; 3, o3 ] diff --git a/compiler/lib/driver.mli b/compiler/lib/driver.mli index 3e24674c18..0ff93bf9bd 100644 --- a/compiler/lib/driver.mli +++ b/compiler/lib/driver.mli @@ -22,7 +22,7 @@ type profile val f : ?standalone:bool - -> ?global:[ `globalThis | `Function | `Bind_to of string | `Custom of string ] + -> ?wrap_with_fun:[ `Iife | `Anonymous | `Named of string ] -> ?profile:profile -> ?dynlink:bool -> ?linkall:bool From 050686b4d71c9b3a0f10ac14b9d344d2e5acda61 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Mon, 3 Jan 2022 14:24:46 +0100 Subject: [PATCH 2/7] Compiler: export to node when using wrap-with-fun, fix #653 --- compiler/lib/driver.ml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/compiler/lib/driver.ml b/compiler/lib/driver.ml index c3df015dd3..e2f1c8f136 100644 --- a/compiler/lib/driver.ml +++ b/compiler/lib/driver.ml @@ -390,7 +390,21 @@ let pack ~wrap_with_fun ~standalone { Linker.runtime_code = js; always_required_ let js = always_required_js @ [ runtime_js ] in let js = match wrap_with_fun, standalone with - | `Named _, _ -> js + | `Named name, (true | false) -> + let export_node = + let s = + Printf.sprintf + {| +if (typeof module === 'object' && module.exports) { + module['exports'] = %s; +} +|} + name + in + let lex = Parse_js.Lexer.of_lexbuf (Lexing.from_string s) in + Parse_js.parse lex + in + js @ export_node | `Anonymous, _ -> js | `Iife, false -> js | `Iife, true -> From c51a1612ecbadc5990734d6cc2e1125f3dd3e1a0 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Mon, 3 Jan 2022 16:18:26 +0100 Subject: [PATCH 3/7] Example: add namespace --- examples/namespace/a.ml | 11 ++++++++++ examples/namespace/b.ml | 11 ++++++++++ examples/namespace/dune | 19 +++++++++++++++++ examples/namespace/index.html | 40 +++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 examples/namespace/a.ml create mode 100644 examples/namespace/b.ml create mode 100644 examples/namespace/dune create mode 100644 examples/namespace/index.html diff --git a/examples/namespace/a.ml b/examples/namespace/a.ml new file mode 100644 index 0000000000..c0929a1874 --- /dev/null +++ b/examples/namespace/a.ml @@ -0,0 +1,11 @@ +let () = print_endline "A" + +exception Exn + +let try_with f = try f () with Exn -> () + +let raise_ () = raise Exn + +let () = Js_of_ocaml.Js.export "tryWith" try_with + +let () = Js_of_ocaml.Js.export "raise" raise_ diff --git a/examples/namespace/b.ml b/examples/namespace/b.ml new file mode 100644 index 0000000000..949b027b3a --- /dev/null +++ b/examples/namespace/b.ml @@ -0,0 +1,11 @@ +let () = print_endline "B" + +exception Exn + +let try_with f = try f () with Exn -> () + +let raise_ () = raise Exn + +let () = Js_of_ocaml.Js.export "tryWith" try_with + +let () = Js_of_ocaml.Js.export "raise" raise_ diff --git a/examples/namespace/dune b/examples/namespace/dune new file mode 100644 index 0000000000..8b97b78ba5 --- /dev/null +++ b/examples/namespace/dune @@ -0,0 +1,19 @@ +(executables + (names a b) + (modes byte) + (libraries js_of_ocaml) +) + +(rule + (target a.js) + (action (run %{bin:js_of_ocaml} %{dep:./a.bc} --wrap-with-fun implemA -o a.js --pretty --target-env browser --no-extern-fs))) + +(rule + (target b.js) + (action (run %{bin:js_of_ocaml} %{dep:./b.bc} --wrap-with-fun implemB -o b.js --pretty --target-env browser --no-extern-fs))) + +(alias + (name default) + (deps + a.js b.js + index.html)) diff --git a/examples/namespace/index.html b/examples/namespace/index.html new file mode 100644 index 0000000000..34b1ec9a34 --- /dev/null +++ b/examples/namespace/index.html @@ -0,0 +1,40 @@ + + + + + Namespaces + + + + + + From 414c7c06b3d666b43d9b96b1e4ca8d95a8119d8a Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Tue, 4 Jan 2022 13:46:57 +0100 Subject: [PATCH 4/7] Compiler: improve exports to node when using wrap-with-fun --- compiler/lib/driver.ml | 40 ++++++++++++++++++---- compiler/lib/generate.ml | 13 +++++--- compiler/lib/generate.mli | 1 + examples/namespace/dune | 11 ++++++- examples/namespace/for-node.js | 51 +++++++++++++++++++++++++++++ examples/namespace/index.html | 12 ++----- lib/js_of_ocaml/js.ml | 4 +-- lib/js_of_ocaml/js_of_ocaml_stubs.c | 4 --- runtime/jslib_js_of_ocaml.js | 10 ------ 9 files changed, 107 insertions(+), 39 deletions(-) create mode 100644 examples/namespace/for-node.js diff --git a/compiler/lib/driver.ml b/compiler/lib/driver.ml index e2f1c8f136..001426814a 100644 --- a/compiler/lib/driver.ml +++ b/compiler/lib/driver.ml @@ -23,6 +23,10 @@ let debug = Debug.find "main" let times = Debug.find "times" +let should_export = function + | `Iife -> false + | `Named _ | `Anonymous -> true + let tailcall p = if debug () then Format.eprintf "Tail-call optimization...@."; Tailcall.f p @@ -140,9 +144,10 @@ let round2 = flow +> specialize' +> eval +> deadcode +> o1 let o3 = loop 10 "tailcall+inline" round1 1 +> loop 10 "flow" round2 1 +> print -let generate d ~exported_runtime (p, live_vars) = +let generate d ~exported_runtime ~wrap_with_fun (p, live_vars) = if times () then Format.eprintf "Start Generation...@."; - Generate.f p ~exported_runtime ~live_vars d + let should_export = should_export wrap_with_fun in + Generate.f p ~exported_runtime ~live_vars ~should_export d let header formatter ~custom_header = (match custom_header with @@ -354,16 +359,39 @@ let pack ~wrap_with_fun ~standalone { Linker.runtime_code = js; always_required_ J.Statement (J.Variable_statement [ J.ident ident, Some (e, J.N) ]), J.N in let expr e = J.Statement (J.Expression_statement e), J.N in - let old_global_object_shim js = + let freenames = let o = new Js_traverse.free in - let js = o#program js in - if StringSet.mem Constant.old_global_object o#get_free_name + let (_ : J.program) = o#program js in + o#get_free_name + in + let export_shim js = + if StringSet.mem "exports" freenames + then + if should_export wrap_with_fun + then var "exports" (J.EObj []) :: js + else + let export_node = + let s = + Printf.sprintf + {|((typeof module === 'object' && module.exports) || %s)|} + global_object + in + let lex = Parse_js.Lexer.of_lexbuf (Lexing.from_string s) in + Parse_js.parse_expr lex + in + var "exports" export_node :: js + else js + in + let old_global_object_shim js = + if StringSet.mem Constant.old_global_object freenames then var Constant.old_global_object (J.EVar (J.ident global_object)) :: js else js in + let efun args body = J.EFun (None, args, body, J.U) in let sfun name args body = J.Function_declaration (name, args, body, J.U), J.U in let mk f = + let js = export_shim js in let js = old_global_object_shim js in let js = if use_strict then expr (J.EStr ("use strict", `Utf8)) :: js else js in f [ J.ident global_object ] js @@ -484,7 +512,7 @@ let full +> deadcode' in let emit = - generate d ~exported_runtime + generate d ~exported_runtime ~wrap_with_fun +> link ~standalone ~linkall ~export_runtime:dynlink +> pack ~wrap_with_fun ~standalone +> coloring diff --git a/compiler/lib/generate.ml b/compiler/lib/generate.ml index 43cd27814f..b286468d8f 100644 --- a/compiler/lib/generate.ml +++ b/compiler/lib/generate.ml @@ -223,10 +223,11 @@ module Ctx = struct ; share : Share.t ; debug : Parse_bytecode.Debug.t ; exported_runtime : (Code.Var.t * bool ref) option + ; should_export : bool } - let initial ~exported_runtime blocks live share debug = - { blocks; live; share; debug; exported_runtime } + let initial ~exported_runtime ~should_export blocks live share debug = + { blocks; live; share; debug; exported_runtime; should_export } end let var x = J.EVar (J.V x) @@ -1671,7 +1672,9 @@ and compile_conditional st queue pc last handler backs frontier interm succs = | Raise (x, k) -> let (_px, cx), queue = access_queue queue x in flush_all queue (throw_statement st.ctx cx k loc) - | Stop -> flush_all queue [ J.Return_statement None, loc ] + | Stop -> + let e_opt = if st.ctx.Ctx.should_export then Some (s_var "exports") else None in + flush_all queue [ J.Return_statement e_opt, loc ] | Branch cont -> compile_branch st queue cont handler backs frontier interm | Pushtrap _ -> assert false | Poptrap (cont, _) -> @@ -1937,13 +1940,13 @@ let compile_program ctx pc = if debug () then Format.eprintf "@.@."; res -let f (p : Code.program) ~exported_runtime ~live_vars debug = +let f (p : Code.program) ~exported_runtime ~live_vars ~should_export debug = let t' = Timer.make () in let share = Share.get ~alias_prims:exported_runtime p in let exported_runtime = if exported_runtime then Some (Code.Var.fresh_n "runtime", ref false) else None in - let ctx = Ctx.initial ~exported_runtime p.blocks live_vars share debug in + let ctx = Ctx.initial ~exported_runtime ~should_export p.blocks live_vars share debug in let p = compile_program ctx p.start in if times () then Format.eprintf " code gen.: %a@." Timer.print t'; p diff --git a/compiler/lib/generate.mli b/compiler/lib/generate.mli index 5aa72939dd..8d719282b9 100644 --- a/compiler/lib/generate.mli +++ b/compiler/lib/generate.mli @@ -22,5 +22,6 @@ val f : Code.program -> exported_runtime:bool -> live_vars:int array + -> should_export:bool -> Parse_bytecode.Debug.t -> Javascript.program diff --git a/examples/namespace/dune b/examples/namespace/dune index 8b97b78ba5..6e4f067e29 100644 --- a/examples/namespace/dune +++ b/examples/namespace/dune @@ -8,6 +8,10 @@ (target a.js) (action (run %{bin:js_of_ocaml} %{dep:./a.bc} --wrap-with-fun implemA -o a.js --pretty --target-env browser --no-extern-fs))) +(rule + (target a-iife.js) + (action (run %{bin:js_of_ocaml} %{dep:./a.bc} -o a-iife.js --target-env browser --no-extern-fs))) + (rule (target b.js) (action (run %{bin:js_of_ocaml} %{dep:./b.bc} --wrap-with-fun implemB -o b.js --pretty --target-env browser --no-extern-fs))) @@ -15,5 +19,10 @@ (alias (name default) (deps - a.js b.js + a.js b.js a-iife.js index.html)) + +(rule + (alias runtest) + (deps a.js b.js a-iife.js for-node.js) + (action (run node for-node.js))) \ No newline at end of file diff --git a/examples/namespace/for-node.js b/examples/namespace/for-node.js new file mode 100644 index 0000000000..61465337b9 --- /dev/null +++ b/examples/namespace/for-node.js @@ -0,0 +1,51 @@ +function shouldRaise(f) { + try { + f(); + throw new Error ("should have raised"); + } catch (e) { console.log("OK"); return } +} +function shouldNotRaise(f) { + try { + f(); + console.log("OK"); + return + } catch (e) { throw new Error ("should have raised"); } +} + +// a0, a1 and b are three separate instances. + +var a0 = require('./a.js')(globalThis); +var a1 = require('./a.js')(globalThis); +var b = require('./b.js')(globalThis); +shouldNotRaise(() => a0.tryWith(a0.raise)); +shouldRaise(() => a1.tryWith(a0.raise)); +shouldRaise(() => b.tryWith(a0.raise)); + +shouldRaise(() => a0.tryWith(a1.raise)); +shouldNotRaise(() => a1.tryWith(a1.raise)); +shouldRaise(() => b.tryWith(a1.raise)); + +shouldRaise(() => a0.tryWith(b.raise)); +shouldRaise(() => a1.tryWith(b.raise)); +shouldNotRaise(() => b.tryWith(b.raise)); + +// a2 is different from a0,a1 and b +var a2 = require('./a-iife.js'); +shouldNotRaise (() => a2.tryWith(a2.raise)); +shouldRaise(() => a0.tryWith(a2.raise)); +shouldRaise(() => a2.tryWith(a0.raise)); +shouldRaise(() => a1.tryWith(a2.raise)); +shouldRaise(() => a2.tryWith(a1.raise)); +shouldRaise(() => b.tryWith(a2.raise)); +shouldRaise(() => a2.tryWith(b.raise)); + +// a3 is the same as a2 +var a3 = require('./a-iife.js'); +shouldNotRaise (() => a2.tryWith(a3.raise)); +shouldNotRaise (() => a3.tryWith(a2.raise)); +shouldRaise(() => a0.tryWith(a3.raise)); +shouldRaise(() => a3.tryWith(a0.raise)); +shouldRaise(() => a1.tryWith(a3.raise)); +shouldRaise(() => a3.tryWith(a1.raise)); +shouldRaise(() => b.tryWith(a3.raise)); +shouldRaise(() => a3.tryWith(b.raise)); diff --git a/examples/namespace/index.html b/examples/namespace/index.html index 34b1ec9a34..24a1be8fdf 100644 --- a/examples/namespace/index.html +++ b/examples/namespace/index.html @@ -8,14 +8,6 @@