@@ -14,36 +14,8 @@ defmodule ElixirScript.Translator.Spawn do
1414
1515 defp do_spawn_with_fn ( { :fn , _ , [ { :-> , _ , [ [ ] , body ] } ] } , env , spawn_func_name ) do
1616 { body , env } = Function . prepare_function_body ( body , % { env | in_process: true } )
17-
18- js_ast = JS . call_expression (
19- JS . member_expression (
20- JS . member_expression (
21- JS . identifier ( "Elixir" ) ,
22- JS . member_expression (
23- JS . identifier ( "Core" ) ,
24- JS . identifier ( "Functions" )
25- )
26- ) ,
27- JS . identifier ( "get_global" )
28- ) ,
29- [ ]
30- )
31-
32-
33- js_ast = JS . call_expression (
34- JS . member_expression (
35- JS . member_expression (
36- js_ast ,
37- JS . identifier ( "processes" )
38- ) ,
39- JS . identifier ( spawn_func_name )
40- ) ,
41- [
42- JS . function_expression ( [ ] , [ ] , JS . block_statement ( body ) , true )
43- ]
44- )
45-
46- { js_ast , env }
17+ js = call_processes_func ( spawn_func_name , [ JS . function_expression ( [ ] , [ ] , JS . block_statement ( body ) , true ) ] )
18+ { js , env }
4719 end
4820
4921 def make_spawn ( module , fun , args , env ) do
@@ -55,19 +27,6 @@ defmodule ElixirScript.Translator.Spawn do
5527 end
5628
5729 defp do_spawn_with_mod ( module , fun , args , env , spawn_func_name ) do
58-
59- js_ast = JS . call_expression (
60- JS . member_expression (
61- JS . member_expression (
62- JS . identifier ( "Elixir" ) ,
63- JS . member_expression (
64- JS . identifier ( "Core" ) ,
65- JS . identifier ( "Functions" )
66- )
67- ) ,
68- JS . identifier ( "get_global" )
69- ) , [ ] )
70-
7130 functions_module = JS . member_expression (
7231 JS . identifier ( "Elixir" ) ,
7332 JS . member_expression (
@@ -92,24 +51,47 @@ defmodule ElixirScript.Translator.Spawn do
9251 JS . identifier ( "null" )
9352 end
9453
54+
55+ js = call_processes_func ( spawn_func_name , [
56+ functions_module ,
57+ JS . literal ( "run" ) ,
58+ JS . array_expression ( [ func_to_run , JS . array_expression ( args ) , context ] )
59+ ] )
60+
61+ { js , env }
62+ end
63+
64+
65+
66+ def call_processes_func ( func_name , params ) do
67+ js_ast = JS . call_expression (
68+ JS . member_expression (
69+ JS . member_expression (
70+ JS . identifier ( "Elixir" ) ,
71+ JS . member_expression (
72+ JS . identifier ( "Core" ) ,
73+ JS . identifier ( "Functions" )
74+ )
75+ ) ,
76+ JS . identifier ( "get_global" )
77+ ) ,
78+ [ ]
79+ )
80+
81+
9582 js_ast = JS . call_expression (
9683 JS . member_expression (
9784 JS . member_expression (
9885 js_ast ,
9986 JS . identifier ( "processes" )
10087 ) ,
101- JS . identifier ( spawn_func_name )
88+ JS . identifier ( func_name )
10289 ) ,
103- [
104- functions_module ,
105- JS . literal ( "run" ) ,
106- JS . array_expression ( [ func_to_run , JS . array_expression ( args ) , context ] )
107- ]
90+ params
10891 )
10992
110- { js_ast , env }
111- end
11293
94+ end
11395
11496
11597end
0 commit comments