Skip to content
This repository has been archived by the owner on Feb 27, 2022. It is now read-only.

Commit

Permalink
Work around missing --allow_natives_syntax
Browse files Browse the repository at this point in the history
Fixes: #14
  • Loading branch information
addaleax authored and isaacs committed Dec 5, 2017
1 parent 548cb7f commit a944f31
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ function req_ (id, cache) {
}
cache[id] = nm
var fn
var setV8Flags = false
try {
require('v8').setFlagsFromString('--allow_natives_syntax')
setV8Flags = true
} catch (e) {}
try {
/* istanbul ignore else */
if (ContextifyScript) {
Expand All @@ -105,6 +110,12 @@ function req_ (id, cache) {
nm.loaded = true
} finally {
nm.loading = false
if (setV8Flags) {
// Ref: https://github.com/nodejs/node/blob/591a24b819d53a555463b1cbf9290a6d8bcc1bcb/lib/internal/bootstrap_node.js#L429-L434
var re = /^--allow[-_]natives[-_]syntax$/
if (!process.execArgv.some(function (s) { return re.test(s) }))
require('v8').setFlagsFromString('--noallow_natives_syntax')
}
}

return nm.exports
Expand Down

0 comments on commit a944f31

Please sign in to comment.