@@ -63,9 +63,18 @@ const writeFile = async (path, data) => {
6363} ;
6464
6565const parseFrontmatter = ( src ) => {
66+ let sharedArrayBufferTest = false ;
67+
68+ var sharedArrayBuffer = src . indexOf ( "sharedarraybuffer" ) ;
69+ if ( sharedArrayBuffer === - 1 ) {
70+ sharedArrayBufferTest = false ;
71+ } else {
72+ sharedArrayBufferTest = true ;
73+ }
74+
6675 var start = src . indexOf ( "/*---" ) ;
6776 var end = src . indexOf ( "---*/" ) ;
68- if ( start === - 1 || end === - 1 ) return null ;
77+ if ( start === - 1 || end === - 1 ) return sharedArrayBufferTest ;
6978
7079 var match ,
7180 includes = [ ] ,
@@ -160,6 +169,7 @@ const parseFrontmatter = (src) => {
160169 flags : flags ,
161170 negative : negative ,
162171 isDynamic : / d y n a m i c - i m p o r t / . test ( frontmatter ) ,
172+ sharedArrayBufferTest : sharedArrayBufferTest
163173 } ; // lol, do better
164174} ;
165175
@@ -189,6 +199,8 @@ const generateTest = async ({
189199 currentPath,
190200 templateContent,
191201 iframeTemplateContent,
202+ headerContent,
203+ headerIFrameContent,
192204} ) => {
193205 if ( ! currentPath ) currentPath = testsPath ;
194206 let stats = await readStats ( currentPath ) ;
@@ -207,6 +219,8 @@ const generateTest = async ({
207219 testsPath,
208220 templateContent,
209221 iframeTemplateContent,
222+ headerContent,
223+ headerIFrameContent,
210224 } ) ;
211225 }
212226 } else {
@@ -217,13 +231,19 @@ const generateTest = async ({
217231 return ;
218232 }
219233
234+ const jsSrc = await readFile ( currentPath ) ;
235+ const meta = parseFrontmatter ( jsSrc ) ;
236+ let isSharedArrayBufferTest = meta . sharedArrayBufferTest ;
237+
220238 const jsRelativePath = path . relative ( testsPath , currentPath ) ;
221239 // console.log(jsRelativePath.replace('.js', ''))
222240 const jsOutputPath = path . join ( outputPath , jsRelativePath ) ;
223- const htmlOutputPath = jsOutputPath . replace ( ".js" , ".html" ) ;
224- const iframeHtmlOutputPath = jsOutputPath . replace ( ".js" , ".iframe.html" ) ;
225- const jsSrc = await readFile ( currentPath ) ;
226- const meta = parseFrontmatter ( jsSrc ) ;
241+ const htmlOutputPath = jsOutputPath . replace ( ".js" , isSharedArrayBufferTest == true ? ".https.html" : ".html" ) ;
242+ const iframeHtmlOutputPath = jsOutputPath . replace ( ".js" , isSharedArrayBufferTest == true ? ".iframe.https.html" : ".iframe.html" ) ;
243+
244+ const htmlOutputHeadersPath = jsOutputPath . replace ( ".js" , ".https.html.headers" ) ;
245+ const iframeHtmlOutputHeadersPath = jsOutputPath . replace ( ".js" , ".iframe.https.html.headers" ) ;
246+
227247 const includes = ( meta && meta . includes ) || [ ] ;
228248 //console.log(includes);
229249 const testContent = replacePlaceholders ( templateContent , {
@@ -240,6 +260,10 @@ const generateTest = async ({
240260
241261 await writeFile ( htmlOutputPath , testContent ) ;
242262 await writeFile ( iframeHtmlOutputPath , iframeTestContent ) ;
263+ if ( isSharedArrayBufferTest ) {
264+ await writeFile ( htmlOutputHeadersPath , headerContent ) ;
265+ await writeFile ( iframeHtmlOutputHeadersPath , headerIFrameContent ) ;
266+ }
243267 await fs . copy ( currentPath , jsOutputPath ) ;
244268 testCount ++ ;
245269 }
@@ -276,6 +300,8 @@ function replacePlaceholders(
276300 __dirname ,
277301 "test-template.iframe.html"
278302 ) ;
303+ const HEADER_TEMPLATE_NAME = path . join ( __dirname , "header-template.html" ) ;
304+ const IFRAME_HEADER_TEMPLATE_NAME = path . join ( __dirname , "header-template.html" ) ;
279305 const DEFAULT_TEST_DIR = "./test262" ;
280306 const DEFAULT_OUTPUT_DIR = "." ;
281307 const SUB_DIR_NAME = "ecmascript" ;
@@ -295,12 +321,16 @@ function replacePlaceholders(
295321 console . log ( "Reading test templates ..." ) ;
296322 const templateContent = await readFile ( HTML_TEMPLATE_NAME ) ;
297323 const iframeTemplateContent = await readFile ( IFRAME_HTML_TEMPLATE_NAME ) ;
324+ const headerContent = await readFile ( HEADER_TEMPLATE_NAME ) ;
325+ const headerIFrameContent = await readFile ( IFRAME_HEADER_TEMPLATE_NAME ) ;
298326 console . log ( "Generating tests ..." ) ;
299327 await generateTest ( {
300328 testsPath,
301329 outputPath : testsOutputPath ,
302330 templateContent,
303331 iframeTemplateContent,
332+ headerContent,
333+ headerIFrameContent,
304334 } ) ;
305335 await fs . copy ( adapterSourcePath , adapterDestinationPath ) ;
306336 await fs . copy ( harnessDir , harnessOutputDir ) ;
0 commit comments