Skip to content

Commit 09c48bd

Browse files
committed
.
1 parent 8f4ab0e commit 09c48bd

File tree

6 files changed

+37
-14
lines changed

6 files changed

+37
-14
lines changed

src/preamble.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ function callRuntimeCallbacks(callbacks) {
428428
}
429429
var func = callback.func;
430430
if (typeof func === 'number') {
431-
dynCallDirect(func, [callback.arg]);
431+
dynCallDirect(func, callback.arg);
432432
} else {
433433
func(callback.arg === undefined ? null : callback.arg);
434434
}

src/preamble_minimal.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,15 @@ var wasmOffsetConverter;
201201
#endif
202202

203203
/** @param {Array=} args */
204-
function dynCallDirect(ptr, args) {
204+
#if ALLOW_ES6
205+
function dynCallDirect(ptr, ...args) {
205206
return wasmTable.get(ptr).apply(null, args);
206207
}
208+
#else
209+
function dynCallDirect(ptr) {
210+
return wasmTable.get(ptr).apply(null, Array.prototype.slice.call(arguments, 1));
211+
}
212+
#endif
207213

208214
#if EXIT_RUNTIME
209215

@@ -216,7 +222,7 @@ function callRuntimeCallbacks(callbacks) {
216222
}
217223
var func = callback.func;
218224
if (typeof func === 'number') {
219-
dynCallDirect(func, [callback.arg]);
225+
dynCallDirect(func, callback.arg);
220226
} else {
221227
func(callback.arg === undefined ? null : callback.arg);
222228
}

src/settings.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,9 @@ var WASM2C = 0;
16111611
// in a custom location.
16121612
var SEPARATE_DWARF_URL = '';
16131613

1614+
// Allow ES6 constructs in the generated JS output
1615+
var ALLOW_ES6 = 0;
1616+
16141617
//===========================================
16151618
// Internal, used for testing only, from here
16161619
//===========================================

src/support.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -577,16 +577,16 @@ function getFuncWrapper(func, sig) {
577577
if (!sigCache[func]) {
578578
// optimize away arguments usage in common cases
579579
if (sig.length === 1) {
580-
sigCache[func] = function() {
580+
sigCache[func] = function dynCall_wrapper() {
581581
return dynCall(sig, func);
582582
};
583583
} else if (sig.length === 2) {
584-
sigCache[func] = function(arg) {
584+
sigCache[func] = function dynCall_wrapper(arg) {
585585
return dynCall(sig, func, [arg]);
586586
};
587587
} else {
588588
// general case
589-
sigCache[func] = function() {
589+
sigCache[func] = function dynCall_wrapper() {
590590
return dynCall(sig, func, Array.prototype.slice.call(arguments));
591591
};
592592
}
@@ -600,19 +600,22 @@ function makeBigInt(low, high, unsigned) {
600600
return unsigned ? ((+((low>>>0)))+((+((high>>>0)))*4294967296.0)) : ((+((low>>>0)))+((+((high|0)))*4294967296.0));
601601
}
602602

603-
/** @param {Array=} args */
604-
function dynCallDirect(ptr, args) {
603+
#if ALLOW_ES6
604+
function dynCallDirect(ptr, ...args) {
605605
return wasmTable.get(ptr).apply(null, args);
606606
}
607+
#else
608+
function dynCallDirect(ptr) {
609+
return wasmTable.get(ptr).apply(null, Array.prototype.slice.call(arguments, 1));
610+
}
611+
#endif
607612

608613
/** @param {Array=} args */
609614
function dynCall(sig, ptr, args) {
610615
#if ASSERTIONS
611616
if (args && args.length) {
612617
// j (64-bit integer) must be passed in as two numbers [low 32, high 32].
613618
assert(args.length === sig.substring(1).replace(/j/g, '--').length);
614-
// j (64-bit integer) must be passed in as two numbers [low 32, high 32].
615-
assert(args.length === sig.substring(1).replace(/j/g, '--').length);
616619
} else {
617620
assert(sig.length == 1);
618621
}
@@ -631,7 +634,11 @@ function dynCall(sig, ptr, args) {
631634
}
632635
#endif
633636

634-
dynCallDirect(ptr, args);
637+
#if ALLOW_ES6
638+
dynCallDirect(ptr, ...args);
639+
#else
640+
dynCallDirect.apply(null, [ptr].concat(args));
641+
#endif
635642
}
636643

637644
var tempRet0 = 0;

tools/building.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,8 +1095,12 @@ def add_to_path(dirname):
10951095
CLOSURE_EXTERNS += [path_from_root('src', 'minimal_runtime_worker_externs.js')]
10961096
outfile = filename + '.cc.js'
10971097

1098+
if Settings.ALLOW_ES6:
1099+
lang = 'ECMASCRIPT6'
1100+
else:
1101+
lang = 'ECMASCRIPT5'
10981102
args = ['--compilation_level', 'ADVANCED_OPTIMIZATIONS' if advanced else 'SIMPLE_OPTIMIZATIONS',
1099-
'--language_in', 'ECMASCRIPT5']
1103+
'--language_in', lang]
11001104
for e in CLOSURE_EXTERNS:
11011105
args += ['--externs', e]
11021106
args += ['--js_output_file', outfile]
@@ -1137,7 +1141,10 @@ def add_to_path(dirname):
11371141
logger.error(proc.stderr) # print list of errors (possibly long wall of text if input was minified)
11381142

11391143
# Exit and print final hint to get clearer output
1140-
exit_with_error('closure compiler failed (rc: %d.%s)', proc.returncode, '' if pretty else ' the error message may be clearer with -g1 and EMCC_DEBUG=2 set')
1144+
msg = 'closure compiler failed (rc: %d): %s' % (proc.returncode, shared.shlex_join(cmd))
1145+
if not pretty:
1146+
msg += ' the error message may be clearer with -g1 and EMCC_DEBUG=2 set'
1147+
exit_with_error(msg)
11411148

11421149
if len(proc.stderr.strip()) > 0 and Settings.CLOSURE_WARNINGS != 'quiet':
11431150
# print list of warnings (possibly long wall of text if input was minified)

tools/shared.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ def make_invoke(sig, named=True):
12291229
if sig[i+1] == 'j':
12301230
new_args[i] = 'BigInt(%s)' % new_args[i]
12311231
new_args = ','.join(new_args)
1232-
body = '%sdynCallDirect(index, [%s]);' % (ret, new_args)
1232+
body = '%sdynCallDirect(index, %s);' % (ret, new_args)
12331233
else:
12341234
body = '%s%s(%s);' % (ret, JS.make_dynCall(sig), args)
12351235
# C++ exceptions are numbers, and longjmp is a string 'longjmp'

0 commit comments

Comments
 (0)