@@ -51,47 +51,15 @@ def ensure_clean_initial_state():
51
51
52
52
# JS harness.
53
53
def replace_js_harness (js_file ):
54
- """
55
- Hack: remove the harness lines generated by the spec interpreter, to later
56
- replace them by our own harness.
57
-
58
- As an alternative, the spec interpreter could take an option that the
59
- harness needs or needs not be generated, which would be cleaner.
60
- """
61
54
test_func_name = os .path .basename (js_file ).replace ('.' , '_' ).replace ('-' , '_' )
62
55
63
- lines = """(function {}() {{
64
-
65
- var $$;""" .format (test_func_name ).split ('\n ' )
66
-
67
- LAST_IGNORED_FUNCTION = 'function assert_return_nan(action) {'
68
-
69
- ignoring = True
70
- reached_end = False
71
-
72
- # Three states machine:
73
- # - ignoring = True and reached_end = False: ignore the line
74
- # - ignoring = True and reached_end = True: last line to be ignored
75
- # - ignoring = False: include the line
76
-
56
+ content = ["(function {}() {{" .format (test_func_name )]
77
57
with open (js_file , 'r' ) as f :
78
- for l in f .readlines ():
79
- l = l .rstrip ()
80
- if ignoring :
81
- if reached_end :
82
- if l == '}' :
83
- ignoring = False
84
- else :
85
- if l == LAST_IGNORED_FUNCTION :
86
- reached_end = True
87
- else :
88
- lines .append (l )
89
-
90
- lines .append ('' )
91
- lines .append ('})();' )
58
+ content += f .readlines ()
59
+ content .append ('})();' )
92
60
93
61
with open (js_file , 'w' ) as f :
94
- f .write ('\n ' .join (lines ))
62
+ f .write ('\n ' .join (content ))
95
63
96
64
def convert_wast_to_js ():
97
65
"""Compile all the wast files to JS and store the results in the JS dir."""
@@ -103,7 +71,7 @@ def convert_wast_to_js():
103
71
print ('Compiling {} to JS...' .format (wast_file ))
104
72
js_filename = os .path .basename (wast_file ) + '.js'
105
73
js_file = os .path .join (OUT_JS_DIR , js_filename )
106
- result = run (WASM_EXEC , wast_file , '-o' , js_file )
74
+ result = run (WASM_EXEC , wast_file , '-h' , '- o' , js_file )
107
75
if result .returncode != 0 :
108
76
print ('Error when compiling {} to JS: {}' , wast_file , result .stdout )
109
77
@@ -117,17 +85,27 @@ def build_js():
117
85
for js_file in glob .glob (os .path .join (JS_DIR , '*.js' )):
118
86
shutil .copy (js_file , OUT_JS_DIR )
119
87
120
- HTML_HEADER = """
121
- <!doctype html>
122
- <title>WebAssembly Web Platform Test</title>
123
- <link rel=author href=mailto:bbouvier@mozilla.com title=bnjbvr>
124
- <script src={PREFIX}lib/testharness.js></script>
125
- <script src={PREFIX}lib/testharnessreport.js></script>
126
- <script src={PREFIX}lib/index.js></script>
127
- <script src={PREFIX}lib/wasm-constants.js></script>
128
- <script src={PREFIX}lib/wasm-module-builder.js></script>
129
-
130
- <div id=log></div>
88
+ HTML_HEADER = """<!doctype html>
89
+ <html>
90
+ <head>
91
+ <meta charset="UTF-8">
92
+ <title>WebAssembly Web Platform Test</title>
93
+ <link rel=author href=mailto:bbouvier@mozilla.com title=bnjbvr>
94
+ </head>
95
+ <body>
96
+
97
+ <script src={PREFIX}lib/testharness.js></script>
98
+ <script src={PREFIX}lib/testharnessreport.js></script>
99
+ <script src={PREFIX}lib/index.js></script>
100
+ <script src={PREFIX}lib/wasm-constants.js></script>
101
+ <script src={PREFIX}lib/wasm-module-builder.js></script>
102
+
103
+ <div id=log></div>
104
+ """
105
+
106
+ HTML_BOTTOM = """
107
+ </body>
108
+ </html>
131
109
"""
132
110
133
111
def build_html_from_js (src_dir ):
@@ -142,22 +120,28 @@ def build_html_from_js(src_dir):
142
120
html_file = os .path .join (OUT_HTML_DIR , html_filename )
143
121
with open (html_file , 'w+' ) as f :
144
122
content = HTML_HEADER .replace ('{PREFIX}' , '../../' )
145
- content += "<script src=../js/{SCRIPT}></script>" .replace ('{SCRIPT}' , js_filename )
123
+ content += " <script src=../js/{SCRIPT}></script>" .replace ('{SCRIPT}' , js_filename )
124
+ content += HTML_BOTTOM
146
125
f .write (content )
147
126
return files
148
127
149
128
def build_html ():
150
129
print ("Building HTML tests..." )
151
130
152
131
print ('Building WPT tests from pure JS tests...' )
153
- js_files = build_html_from_js (OUT_JS_DIR ) + build_html_from_js (HTML_DIR )
132
+ js_files = build_html_from_js (OUT_JS_DIR )
133
+
134
+ print ('Building WPT tests from HTML JS tests...' )
135
+ js_files += build_html_from_js (HTML_DIR )
154
136
155
137
print ('Building front page containing all the HTML tests...' )
156
138
front_page = os .path .join (OUT_DIR , 'index.html' )
157
139
with open (front_page , 'w+' ) as f :
158
140
content = HTML_HEADER .replace ('{PREFIX}' , '../' )
159
141
for filename in js_files :
160
- content += "<script src=./js/{SCRIPT}></script>\n " .replace ('{SCRIPT}' , filename )
142
+ content += " <script src=./js/{SCRIPT}></script>\n " .replace ('{SCRIPT}' , filename )
143
+ content += " <script>reinitializeRegistry();</script>\n "
144
+ content += HTML_BOTTOM
161
145
f .write (content )
162
146
163
147
if __name__ == '__main__' :
0 commit comments