| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bbbba76 commit 43e947a
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,21 +46,6 @@ rules: | |||
| 46 | 46 | node-core/non-ascii-character: error | |
| 47 | 47 | globals: | |
| 48 | 48 | Intl: false | |
| 49 | - # Assertions | ||
| 50 | - CHECK: false | ||
| 51 | - CHECK_EQ: false | ||
| 52 | - CHECK_GE: false | ||
| 53 | - CHECK_GT: false | ||
| 54 | - CHECK_LE: false | ||
| 55 | - CHECK_LT: false | ||
| 56 | - CHECK_NE: false | ||
| 57 | - DCHECK: false | ||
| 58 | - DCHECK_EQ: false | ||
| 59 | - DCHECK_GE: false | ||
| 60 | - DCHECK_GT: false | ||
| 61 | - DCHECK_LE: false | ||
| 62 | - DCHECK_LT: false | ||
| 63 | - DCHECK_NE: false | ||
| 64 | 49 | # Parameters passed to internal modules | |
| 65 | 50 | global: false | |
| 66 | 51 | require: false | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | + const { fail } = require('internal/assert'); | ||
| 3 | 4 | const { | |
| 4 | 5 | ArrayIsArray, | |
| 5 | 6 | ObjectCreate, | |
@@ -58,6 +59,11 @@ const kContext = Symbol('kContext'); | |||
| 58 | 59 | const kPerContextModuleId = Symbol('kPerContextModuleId'); | |
| 59 | 60 | const kLink = Symbol('kLink'); | |
| 60 | 61 | ||
| 62 | + function failIfDebug() { | ||
| 63 | + if (process.features.debug === false) return; | ||
| 64 | + fail('VM Modules'); | ||
| 65 | + } | ||
| 66 | + | ||
| 61 | 67 | class Module { | |
| 62 | 68 | constructor(options) { | |
| 63 | 69 | emitExperimentalWarning('VM Modules'); | |
@@ -118,7 +124,7 @@ class Module { | |||
| 118 | 124 | syntheticExportNames, | |
| 119 | 125 | syntheticEvaluationSteps); | |
| 120 | 126 | } else { | |
| 121 | - CHECK(false); | ||
| 127 | + failIfDebug(); | ||
| 122 | 128 | } | |
| 123 | 129 | ||
| 124 | 130 | wrapToModuleMap.set(this[kWrap], this); | |
@@ -374,7 +380,7 @@ class SyntheticModule extends Module { | |||
| 374 | 380 | identifier, | |
| 375 | 381 | }); | |
| 376 | 382 | ||
| 377 | - this[kLink] = () => this[kWrap].link(() => { CHECK(false); }); | ||
| 383 | + this[kLink] = () => this[kWrap].link(() => { failIfDebug(); }); | ||
| 378 | 384 | } | |
| 379 | 385 | ||
| 380 | 386 | setExport(name, value) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -892,23 +892,11 @@ | |||
| 892 | 892 | # Put the code first so it's a dependency and can be used for invocation. | |
| 893 | 893 | 'tools/js2c.py', | |
| 894 | 894 | '<@(library_files)', | |
| 895 | - 'config.gypi', | ||
| 896 | - 'tools/js2c_macros/check_macros.py' | ||
| 895 | + 'config.gypi' | ||
| 897 | 896 | ], | |
| 898 | 897 | 'outputs': [ | |
| 899 | 898 | '<(SHARED_INTERMEDIATE_DIR)/node_javascript.cc', | |
| 900 | 899 | ], | |
| 901 | - 'conditions': [ | ||
| 902 | - [ 'node_use_dtrace=="false" and node_use_etw=="false"', { | ||
| 903 | - 'inputs': [ 'tools/js2c_macros/notrace_macros.py' ] | ||
| 904 | - }], | ||
| 905 | - [ 'node_debug_lib=="false"', { | ||
| 906 | - 'inputs': [ 'tools/js2c_macros/nodcheck_macros.py' ] | ||
| 907 | - }], | ||
| 908 | - [ 'node_debug_lib=="true"', { | ||
| 909 | - 'inputs': [ 'tools/js2c_macros/dcheck_macros.py' ] | ||
| 910 | - }] | ||
| 911 | - ], | ||
| 912 | 900 | 'action': [ | |
| 913 | 901 | 'python', '<@(_inputs)', | |
| 914 | 902 | '--target', '<@(_outputs)', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,137 +45,6 @@ def ReadFile(filename): | |||
| 45 | 45 | return lines | |
| 46 | 46 | ||
| 47 | 47 | ||
| 48 | - def ReadMacroFiles(filenames): | ||
| 49 | - """ | ||
| 50 | - | ||
| 51 | - :rtype: List(str) | ||
| 52 | - """ | ||
| 53 | - result = [] | ||
| 54 | - for filename in filenames: | ||
| 55 | - with open(filename, "rt") as f: | ||
| 56 | - # strip python-like comments and whitespace padding | ||
| 57 | - lines = [line.split('#')[0].strip() for line in f] | ||
| 58 | - # filter empty lines | ||
| 59 | - result.extend(filter(bool, lines)) | ||
| 60 | - return result | ||
| 61 | - | ||
| 62 | - | ||
| 63 | - def ExpandConstants(lines, constants): | ||
| 64 | - for key, value in constants.items(): | ||
| 65 | - lines = lines.replace(key, str(value)) | ||
| 66 | - return lines | ||
| 67 | - | ||
| 68 | - | ||
| 69 | - def ExpandMacros(lines, macros): | ||
| 70 | - def expander(s): | ||
| 71 | - return ExpandMacros(s, macros) | ||
| 72 | - | ||
| 73 | - for name, macro in macros.items(): | ||
| 74 | - name_pattern = re.compile("\\b%s\\(" % name) | ||
| 75 | - pattern_match = name_pattern.search(lines, 0) | ||
| 76 | - while pattern_match is not None: | ||
| 77 | - # Scan over the arguments | ||
| 78 | - height = 1 | ||
| 79 | - start = pattern_match.start() | ||
| 80 | - end = pattern_match.end() | ||
| 81 | - assert lines[end - 1] == '(' | ||
| 82 | - last_match = end | ||
| 83 | - arg_index = [0] # Wrap state into array, to work around Python "scoping" | ||
| 84 | - mapping = {} | ||
| 85 | - | ||
| 86 | - def add_arg(s): | ||
| 87 | - # Remember to expand recursively in the arguments | ||
| 88 | - if arg_index[0] >= len(macro.args): | ||
| 89 | - return | ||
| 90 | - replacement = expander(s.strip()) | ||
| 91 | - mapping[macro.args[arg_index[0]]] = replacement | ||
| 92 | - arg_index[0] += 1 | ||
| 93 | - | ||
| 94 | - while end < len(lines) and height > 0: | ||
| 95 | - # We don't count commas at higher nesting levels. | ||
| 96 | - if lines[end] == ',' and height == 1: | ||
| 97 | - add_arg(lines[last_match:end]) | ||
| 98 | - last_match = end + 1 | ||
| 99 | - elif lines[end] in ['(', '{', '[']: | ||
| 100 | - height = height + 1 | ||
| 101 | - elif lines[end] in [')', '}', ']']: | ||
| 102 | - height = height - 1 | ||
| 103 | - end = end + 1 | ||
| 104 | - # Remember to add the last match. | ||
| 105 | - add_arg(lines[last_match:end - 1]) | ||
| 106 | - if arg_index[0] < len(macro.args) - 1: | ||
| 107 | - lineno = lines.count(os.linesep, 0, start) + 1 | ||
| 108 | - raise Exception( | ||
| 109 | - 'line %s: Too few arguments for macro "%s"' % (lineno, name)) | ||
| 110 | - result = macro.expand(mapping) | ||
| 111 | - # Replace the occurrence of the macro with the expansion | ||
| 112 | - lines = lines[:start] + result + lines[end:] | ||
| 113 | - pattern_match = name_pattern.search(lines, start + len(result)) | ||
| 114 | - return lines | ||
| 115 | - | ||
| 116 | - | ||
| 117 | - class TextMacro: | ||
| 118 | - def __init__(self, args, body): | ||
| 119 | - self.args = args | ||
| 120 | - self.body = body | ||
| 121 | - | ||
| 122 | - def expand(self, mapping): | ||
| 123 | - result = self.body | ||
| 124 | - for key, value in mapping.items(): | ||
| 125 | - result = result.replace(key, value) | ||
| 126 | - return result | ||
| 127 | - | ||
| 128 | - | ||
| 129 | - class PythonMacro: | ||
| 130 | - def __init__(self, args, fun): | ||
| 131 | - self.args = args | ||
| 132 | - self.fun = fun | ||
| 133 | - | ||
| 134 | - def expand(self, mapping): | ||
| 135 | - args = [] | ||
| 136 | - for arg in self.args: | ||
| 137 | - args.append(mapping[arg]) | ||
| 138 | - return str(self.fun(*args)) | ||
| 139 | - | ||
| 140 | - | ||
| 141 | - CONST_PATTERN = re.compile('^const\s+([a-zA-Z0-9_]+)\s*=\s*([^;]*);$') | ||
| 142 | - MACRO_PATTERN = re.compile('^macro\s+([a-zA-Z0-9_]+)\s*\(([^)]*)\)\s*=\s*([^;]*);$') | ||
| 143 | - PYTHON_MACRO_PATTERN = re.compile('^python\s+macro\s+([a-zA-Z0-9_]+)\s*\(([^)]*)\)\s*=\s*([^;]*);$') | ||
| 144 | - | ||
| 145 | - | ||
| 146 | - def ReadMacros(macro_files): | ||
| 147 | - lines = ReadMacroFiles(macro_files) | ||
| 148 | - constants = {} | ||
| 149 | - macros = {} | ||
| 150 | - for line in lines: | ||
| 151 | - line = line.split('#')[0].strip() | ||
| 152 | - if len(line) == 0: | ||
| 153 | - continue | ||
| 154 | - const_match = CONST_PATTERN.match(line) | ||
| 155 | - if const_match: | ||
| 156 | - name = const_match.group(1) | ||
| 157 | - value = const_match.group(2).strip() | ||
| 158 | - constants[name] = value | ||
| 159 | - else: | ||
| 160 | - macro_match = MACRO_PATTERN.match(line) | ||
| 161 | - if macro_match: | ||
| 162 | - name = macro_match.group(1) | ||
| 163 | - args = [p.strip() for p in macro_match.group(2).split(',')] | ||
| 164 | - body = macro_match.group(3).strip() | ||
| 165 | - macros[name] = TextMacro(args, body) | ||
| 166 | - else: | ||
| 167 | - python_match = PYTHON_MACRO_PATTERN.match(line) | ||
| 168 | - if python_match: | ||
| 169 | - name = python_match.group(1) | ||
| 170 | - args = [p.strip() for p in macro_match.group(2).split(',')] | ||
| 171 | - body = python_match.group(3).strip() | ||
| 172 | - fun = eval("lambda " + ",".join(args) + ': ' + body) | ||
| 173 | - macros[name] = PythonMacro(args, fun) | ||
| 174 | - else: | ||
| 175 | - raise Exception("Illegal line: " + line) | ||
| 176 | - return constants, macros | ||
| 177 | - | ||
| 178 | - | ||
| 179 | 48 | TEMPLATE = """ | |
| 180 | 49 | #include "env-inl.h" | |
| 181 | 50 | #include "node_native_module.h" | |
@@ -243,10 +112,8 @@ def GetDefinition(var, source, step=30): | |||
| 243 | 112 | return definition, len(code_points) | |
| 244 | 113 | ||
| 245 | 114 | ||
| 246 | - def AddModule(filename, consts, macros, definitions, initializers): | ||
| 115 | + def AddModule(filename, definitions, initializers): | ||
| 247 | 116 | code = ReadFile(filename) | |
| 248 | - code = ExpandConstants(code, consts) | ||
| 249 | - code = ExpandMacros(code, macros) | ||
| 250 | 117 | name = NormalizeFileName(filename) | |
| 251 | 118 | slug = SLUGGER_RE.sub('_', name) | |
| 252 | 119 | var = slug + '_raw' | |
@@ -267,15 +134,12 @@ def NormalizeFileName(filename): | |||
| 267 | 134 | ||
| 268 | 135 | ||
| 269 | 136 | def JS2C(source_files, target): | |
| 270 | - # Process input from all *macro.py files | ||
| 271 | - consts, macros = ReadMacros(source_files['.py']) | ||
| 272 | - | ||
| 273 | 137 | # Build source code lines | |
| 274 | 138 | definitions = [] | |
| 275 | 139 | initializers = [] | |
| 276 | 140 | ||
| 277 | 141 | for filename in source_files['.js']: | |
| 278 | - AddModule(filename, consts, macros, definitions, initializers) | ||
| 142 | + AddModule(filename, definitions, initializers) | ||
| 279 | 143 | ||
| 280 | 144 | config_def, config_size = handle_config_gypi(source_files['config.gypi']) | |
| 281 | 145 | definitions.append(config_def) | |
@@ -341,8 +205,8 @@ def main(): | |||
| 341 | 205 | global is_verbose | |
| 342 | 206 | is_verbose = options.verbose | |
| 343 | 207 | source_files = functools.reduce(SourceFileByExt, options.sources, {}) | |
| 344 | - # Should have exactly 3 types: `.js`, `.py`, and `.gypi` | ||
| 345 | - assert len(source_files) == 3 | ||
| 208 | + # Should have exactly 2 types: `.js`, and `.gypi` | ||
| 209 | + assert len(source_files) == 2 | ||
| 346 | 210 | # Currently config.gypi is the only `.gypi` file allowed | |
| 347 | 211 | assert source_files['.gypi'] == ['config.gypi'] | |
| 348 | 212 | source_files['config.gypi'] = source_files.pop('.gypi')[0] | |
| Back | FazBrowse Home | New Git URL |
0 commit comments