diff --git a/EMCASCRIPT.md b/EMCASCRIPT.md index 25d09222be..94ef17b77f 100644 --- a/EMCASCRIPT.md +++ b/EMCASCRIPT.md @@ -6,6 +6,8 @@ Features are grouped by ECMAScript version. ## ECMAScript 2015 - ES6 ### rest parameters - added in Nodejs 6 +### spread in function call +- added in Nodejs 5 ### Object.assign - added In Nodejs 4 ### ArrowFunction diff --git a/compiler/lib-runtime-files/tests/all.ml b/compiler/lib-runtime-files/tests/all.ml index 282ecce3fc..bd76636f7d 100644 --- a/compiler/lib-runtime-files/tests/all.ml +++ b/compiler/lib-runtime-files/tests/all.ml @@ -45,7 +45,6 @@ let%expect_test _ = +prng.js +runtime_events.js +stdlib.js - +stdlib_modern.js +str.js +sync.js +sys.js @@ -98,5 +97,4 @@ let%expect_test _ = printl extra; [%expect {| +dynlink.js - +stdlib_modern.js +toplevel.js |}] diff --git a/compiler/tests-compiler/gh1051.ml b/compiler/tests-compiler/gh1051.ml index 864417a6a7..6f0406d7bf 100644 --- a/compiler/tests-compiler/gh1051.ml +++ b/compiler/tests-compiler/gh1051.ml @@ -22,7 +22,7 @@ let prog = {|let () = Printf.printf "%nx" 0xffffffffn;;|} let%expect_test _ = - Util.compile_and_run ~skip_modern:true prog; + Util.compile_and_run prog; [%expect {| Warning: integer overflow: native integer 0xffffffff (4294967295) truncated to 0xffffffff (-1); the generated code might be incorrect. diff --git a/compiler/tests-compiler/util/util.ml b/compiler/tests-compiler/util/util.ml index 74cf3cec92..02e9604670 100644 --- a/compiler/tests-compiler/util/util.ml +++ b/compiler/tests-compiler/util/util.ml @@ -566,15 +566,7 @@ let compile_and_run_bytecode ?unix s = |> run_bytecode |> print_endline) -let compile_and_run - ?debug - ?pretty - ?(skip_modern = false) - ?(flags = []) - ?effects - ?use_js_string - ?unix - s = +let compile_and_run ?debug ?pretty ?(flags = []) ?effects ?use_js_string ?unix s = with_temp_dir ~f:(fun () -> let bytecode_file = s @@ -582,7 +574,7 @@ let compile_and_run |> Filetype.write_ocaml ~name:"test.ml" |> compile_ocaml_to_bc ?debug ?unix in - let output_without_stdlib_modern = + let output = compile_bc_to_javascript ?pretty ~flags @@ -592,24 +584,7 @@ let compile_and_run bytecode_file |> run_javascript in - print_endline output_without_stdlib_modern; - if not skip_modern - then - let output_with_stdlib_modern = - compile_bc_to_javascript - ~flags:(flags @ [ "+stdlib_modern.js" ]) - ?effects - ?use_js_string - ?sourcemap:debug - bytecode_file - |> run_javascript - in - if not (String.equal output_without_stdlib_modern output_with_stdlib_modern) - then ( - print_endline "Output was different with stdlib_modern.js:"; - print_endline "==========================================="; - print_string output_with_stdlib_modern; - print_endline "===========================================")) + print_endline output) let compile_and_parse_whole_program ?(debug = true) diff --git a/compiler/tests-compiler/util/util.mli b/compiler/tests-compiler/util/util.mli index 511933b9b0..a507a53bb2 100644 --- a/compiler/tests-compiler/util/util.mli +++ b/compiler/tests-compiler/util/util.mli @@ -81,7 +81,6 @@ val print_double_fun_decl : Javascript.program -> string -> unit val compile_and_run : ?debug:bool -> ?pretty:bool - -> ?skip_modern:bool -> ?flags:string list -> ?effects:[ `Disabled | `Cps | `Double_translation ] -> ?use_js_string:bool diff --git a/runtime/js/stdlib.js b/runtime/js/stdlib.js index 87e5f6d801..a0e83f2302 100644 --- a/runtime/js/stdlib.js +++ b/runtime/js/stdlib.js @@ -24,9 +24,9 @@ function caml_call_gen(f, args) { var n = f.l >= 0 ? f.l : (f.l = f.length); var argsLen = args.length; var d = n - argsLen; - if (d === 0) return f.apply(null, args); + if (d === 0) return f(...args); else if (d < 0) { - var g = f.apply(null, args.slice(0, n)); + var g = f(...args.slice(0, n)); if (typeof g !== "function") return g; return caml_call_gen(g, args.slice(n)); } else { @@ -36,7 +36,7 @@ function caml_call_gen(f, args) { var nargs = new Array(argsLen + 1); for (var i = 0; i < argsLen; i++) nargs[i] = args[i]; nargs[argsLen] = x; - return f.apply(null, nargs); + return f(...nargs); }; break; } @@ -46,7 +46,7 @@ function caml_call_gen(f, args) { for (var i = 0; i < argsLen; i++) nargs[i] = args[i]; nargs[argsLen] = x; nargs[argsLen + 1] = y; - return f.apply(null, nargs); + return f(...nargs); }; break; } @@ -70,8 +70,9 @@ function caml_call_gen(f, args) { var n = f.l >= 0 ? f.l : (f.l = f.length); var argsLen = args.length; var d = n - argsLen; - if (d === 0) return f.apply(null, args); - else if (d < 0) { + if (d === 0) { + return f(...args); + } else if (d < 0) { var rest = args.slice(n - 1); var k = args[argsLen - 1]; args = args.slice(0, n); @@ -81,7 +82,7 @@ function caml_call_gen(f, args) { args[args.length - 1] = k; return caml_call_gen(g, args); }; - return f.apply(null, args); + return f(...args); } else { argsLen--; var k = args[argsLen]; @@ -92,7 +93,7 @@ function caml_call_gen(f, args) { for (var i = 0; i < argsLen; i++) nargs[i] = args[i]; nargs[argsLen] = x; nargs[argsLen + 1] = y; - return f.apply(null, nargs); + return f(...nargs); }; break; } @@ -103,7 +104,7 @@ function caml_call_gen(f, args) { nargs[argsLen] = x; nargs[argsLen + 1] = y; nargs[argsLen + 2] = z; - return f.apply(null, nargs); + return f(...nargs); }; break; } diff --git a/runtime/js/stdlib_modern.js b/runtime/js/stdlib_modern.js deleted file mode 100644 index ba47bdc341..0000000000 --- a/runtime/js/stdlib_modern.js +++ /dev/null @@ -1,205 +0,0 @@ -// Js_of_ocaml runtime support -// http://www.ocsigen.org/js_of_ocaml/ -// Laboratoire PPS - CNRS Université Paris Diderot -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, with linking exception; -// either version 2.1 of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -//Provides: caml_call_gen (const, shallow) -//If: !effects -function caml_call_gen(f, args) { - var n = f.l >= 0 ? f.l : (f.l = f.length); - var argsLen = args.length; - var d = n - argsLen; - if (d === 0) return f(...args); - else if (d < 0) { - var g = f(...args.slice(0, n)); - if (typeof g !== "function") return g; - return caml_call_gen(g, args.slice(n)); - } else { - switch (d) { - case 1: { - var g = function (x) { - var nargs = new Array(argsLen + 1); - for (var i = 0; i < argsLen; i++) nargs[i] = args[i]; - nargs[argsLen] = x; - return f.apply(null, nargs); - }; - break; - } - case 2: { - var g = function (x, y) { - var nargs = new Array(argsLen + 2); - for (var i = 0; i < argsLen; i++) nargs[i] = args[i]; - nargs[argsLen] = x; - nargs[argsLen + 1] = y; - return f.apply(null, nargs); - }; - break; - } - default: { - var g = function (...extra_args) { - if (extra_args.length === 0) extra_args = [undefined]; - return caml_call_gen(f, args.concat(extra_args)); - }; - } - } - g.l = d; - return g; - } -} - -//Provides: caml_call_gen (const, shallow) -//If: effects -//If: !doubletranslate -//Weakdef -function caml_call_gen(f, args) { - var n = f.l >= 0 ? f.l : (f.l = f.length); - var argsLen = args.length; - var d = n - argsLen; - if (d === 0) return f(...args); - else if (d < 0) { - var rest = args.slice(n - 1); - var k = args[argsLen - 1]; - args = args.slice(0, n); - args[n - 1] = function (g) { - if (typeof g !== "function") return k(g); - var args = rest.slice(); - args[args.length - 1] = k; - return caml_call_gen(g, args); - }; - return f(...args); - } else { - argsLen--; - var k = args[argsLen]; - switch (d) { - case 1: { - var g = function (x, y) { - var nargs = new Array(argsLen + 2); - for (var i = 0; i < argsLen; i++) nargs[i] = args[i]; - nargs[argsLen] = x; - nargs[argsLen + 1] = y; - return f.apply(null, nargs); - }; - break; - } - case 2: { - var g = function (x, y, z) { - var nargs = new Array(argsLen + 3); - for (var i = 0; i < argsLen; i++) nargs[i] = args[i]; - nargs[argsLen] = x; - nargs[argsLen + 1] = y; - nargs[argsLen + 2] = z; - return f.apply(null, nargs); - }; - break; - } - default: { - args.length = argsLen; - var g = function (...extra_args) { - if (extra_args.length === 0) extra_args = [undefined]; - return caml_call_gen(f, args.concat(extra_args)); - }; - } - } - g.l = d + 1; - return k(g); - } -} - -//Provides: caml_call_gen_tuple (const, shallow) -//Requires: caml_fiber_stack, caml_cps_closure -//If: effects -//If: doubletranslate -//Weakdef -var caml_call_gen_tuple = (function () { - function caml_call_gen_direct(f, args) { - var n = f.l >= 0 ? f.l : (f.l = f.length); - var argsLen = args.length; - var d = n - argsLen; - if (d === 0) { - return f(...args); - } else if (d < 0) { - return caml_call_gen_direct(f.apply(...args.slice(0, n)), args.slice(n)); - } else { - // FIXME: Restore the optimization of handling specially d = 1 or 2 - var args_ = args.slice(); - args_.length = argsLen; - var ret = caml_cps_closure( - function (...extra_args) { - if (extra_args.length === 0) extra_args = [undefined]; - return caml_call_gen_direct(f, args.concat(extra_args)); - }, - function (...extra_args) { - if (extra_args.length === 0) extra_args = [undefined]; - return caml_call_gen_cps(f, args_.concat(extra_args)); - }, - ); - ret.l = d; - ret.cps.l = d + 1; - return ret; - } - } - function caml_call_gen_cps(f, args) { - var n = f.cps.l >= 0 ? f.cps.l : (f.cps.l = f.cps.length); - var argsLen = args.length; - var d = n - argsLen; - if (d === 0) { - return f.cps(...args); - } else if (d < 0) { - var rest = args.slice(n - 1); - var k = args[argsLen - 1]; - args = args.slice(0, n); - args[n - 1] = function (g) { - var args = rest.slice(); - args[args.length - 1] = k; - return caml_call_gen_cps(g, args); - }; - return f.cps(...args); - } else { - argsLen--; - var args_ = args.slice(); - args_.length = argsLen; - var cont = caml_cps_closure( - function (...extra_args) { - if (extra_args.length === 0) extra_args = [undefined]; - return caml_call_gen_direct(f, args_.concat(extra_args)); - }, - function (...extra_args) { - if (extra_args.length === 0) extra_args = [undefined]; - return caml_call_gen_cps(f, args_.concat(extra_args)); - }, - ); - var k = args[argsLen]; - cont.l = d; - cont.cps.l = d + 1; - return k(cont); - } - } - return [caml_call_gen_direct, caml_call_gen_cps]; -})(); - -//Provides: caml_call_gen -//Requires: caml_call_gen_tuple -//If: effects -//If: doubletranslate -//Weakdef -var caml_call_gen = caml_call_gen_tuple[0]; - -//Provides: caml_call_gen_cps -//Requires: caml_call_gen_tuple -//If: effects -//If: doubletranslate -//Weakdef -var caml_call_gen_cps = caml_call_gen_tuple[1];