Skip to content

Commit

Permalink
Remove str-to-func eval of named function factory
Browse files Browse the repository at this point in the history
For support for this feature see:
ttps://caniuse.com/mdn-javascript_operators_object_initializer_computed_property_names

Based on #17296
  • Loading branch information
NickCarducci authored and sbc100 committed Feb 14, 2023
1 parent e04f291 commit 8a702c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
20 changes: 5 additions & 15 deletions src/embind/embind.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,21 +198,11 @@ var LibraryEmbind = {
$createNamedFunction__deps: ['$makeLegalFunctionName'],
$createNamedFunction: function(name, body) {
name = makeLegalFunctionName(name);
#if DYNAMIC_EXECUTION == 0
return function() {
"use strict";
return body.apply(this, arguments);
};
#else
/*jshint evil:true*/
return new Function(
"body",
"return function " + name + "() {\n" +
" \"use strict\";" +
" return body.apply(this, arguments);\n" +
"};\n"
)(body);
#endif
return {
[name]: function () {
return body.apply(this, arguments);
}
}[name];
},

$embindRepr: function(v) {
Expand Down
19 changes: 13 additions & 6 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -12370,6 +12370,13 @@ def test_es5_transpile(self, args):
// arror funcs + const
const bar = () => 2;
err('bar: ' + bar());

// Computed property names
var key = 'mykey';
var obj2 = {
[key]: 42,
};
err('value: ' + obj2[key]);
}
});
''')
Expand Down Expand Up @@ -12403,19 +12410,19 @@ def check_for_es6(filename, expect):
print('with old browser')
self.emcc_args.remove('-Werror')
self.set_setting('MIN_CHROME_VERSION', '10')
self.do_runf('test.c', 'prop: 1\nbar: 2\n', output_basename='test2')
check_for_es6('test2.js', False)
self.do_runf('test.c', 'prop: 1\nbar: 2\n', output_basename='test_old')
check_for_es6('test_old.js', False)

# If we add `--closure=0` that transpiler (closure) is not run at all
print('with old browser + --closure=0')
self.do_runf('test.c', 'prop: 1\nbar: 2\n', emcc_args=['--closure=0'], output_basename='test3')
check_for_es6('test3.js', True)
self.do_runf('test.c', 'prop: 1\nbar: 2\n', emcc_args=['--closure=0'], output_basename='test_no_closure')
check_for_es6('test_no_closure.js', True)

# If we use `--closure=1` closure will run in full optimization mode
# and also transpile to ES5
print('with old browser + --closure=1')
self.do_runf('test.c', 'prop: 1\nbar: 2\n', emcc_args=['--closure=1'], output_basename='test4')
check_for_es6('test4.js', False)
self.do_runf('test.c', 'prop: 1\nbar: 2\n', emcc_args=['--closure=1'], output_basename='test_closure')
check_for_es6('test_closure.js', False)

def test_gmtime_noleak(self):
# Confirm that gmtime_r does not leak when called in isolation.
Expand Down

0 comments on commit 8a702c5

Please sign in to comment.