@@ -2,7 +2,6 @@ const { AstLoader } = require('./ast.js');
22const process = require ( 'process' ) ;
33const commands = require ( './commands/all.js' ) ;
44const consts = require ( './consts.js' ) ;
5- const path = require ( 'path' ) ;
65const { stripCommonPathsPrefix } = require ( './utils.js' ) ;
76
87const ORDERS = {
@@ -117,6 +116,7 @@ const ORDERS = {
117116 'wait-for-text-false' : commands . parseWaitForTextFalse ,
118117 'wait-for-window-property' : commands . parseWaitForWindowProperty ,
119118 'wait-for-window-property-false' : commands . parseWaitForWindowPropertyFalse ,
119+ 'within-iframe' : commands . parseWithinIFrame ,
120120 'write' : commands . parseWrite ,
121121 'write-into' : commands . parseWriteInto ,
122122} ;
@@ -164,6 +164,7 @@ const FATAL_ERROR_COMMANDS = [
164164 'wait-for-property-false' ,
165165 'wait-for-text' ,
166166 'wait-for-text-false' ,
167+ 'within-iframe' ,
167168 'write' ,
168169 'write-into' ,
169170] ;
@@ -262,64 +263,6 @@ class ParserWithContext {
262263 }
263264 }
264265
265- setup_user_function_call ( ast ) {
266- const ret = commands . parseCallFunction ( this ) ;
267- if ( ret . error !== undefined ) {
268- ret . line = this . get_current_command_line ( ) ;
269- if ( ast . length !== 0 ) {
270- ret . error += ` (from command \`${ ast [ 0 ] . getErrorText ( ) } \`)` ;
271- }
272- return ret ;
273- }
274- const args = Object . create ( null ) ;
275- const func = this . definedFunctions [ ret [ 'function' ] ] ;
276- for ( const arg_name of func [ 'arguments' ] ) {
277- const index = ret [ 'args' ] . findIndex ( arg => arg . key . value === arg_name ) ;
278- if ( index === - 1 ) {
279- return {
280- 'error' : `Missing argument "${ arg_name } "` ,
281- 'line' : this . get_current_command_line ( ) ,
282- 'fatal_error' : true ,
283- } ;
284- }
285- args [ arg_name ] = ret [ 'args' ] [ index ] . value ;
286- }
287- const context = this . get_current_context ( ) ;
288- this . pushNewContext ( {
289- 'ast' : context . ast ,
290- 'commands' : func . commands ,
291- 'currentCommand' : 0 ,
292- 'functionArgs' : Object . assign ( { } , context . functionArgs , args ) ,
293- 'filePath' : func . filePath ,
294- } ) ;
295- // We disable the `increasePos` in the context to prevent it to be done twice.
296- return this . get_next_command ( false ) ;
297- }
298-
299- setup_include ( ) {
300- const ret = commands . parseInclude ( this ) ;
301- if ( ret . error !== undefined ) {
302- ret . line = this . get_current_command_line ( ) ;
303- if ( ast . length !== 0 ) {
304- ret . error += ` (from command \`${ ast [ 0 ] . getErrorText ( ) } \`)` ;
305- }
306- return ret ;
307- }
308- const dirPath = path . dirname ( this . get_current_context ( ) . ast . absolutePath ) ;
309- const ast = new AstLoader ( ret . path , dirPath ) ;
310- if ( ast . hasErrors ( ) ) {
311- return { 'errors' : ast . errors } ;
312- }
313- this . pushNewContext ( {
314- 'ast' : ast ,
315- 'commands' : ast . commands ,
316- 'currentCommand' : 0 ,
317- 'functionArgs' : Object . create ( null ) ,
318- } ) ;
319- // We disable the `increasePos` in the context to prevent it to be done twice.
320- return this . get_next_command ( false ) ;
321- }
322-
323266 getCurrentFile ( ) {
324267 const context = this . get_current_context ( ) ;
325268 if ( context === null ) {
@@ -330,19 +273,12 @@ class ParserWithContext {
330273 return context . ast . absolutePath ;
331274 }
332275
333- run_order ( order , ast ) {
276+ run_order ( pages , order , ast ) {
334277 // This is needed because for now, all commands get access to the ast
335278 // through `ParserWithContext`.
336279 this . elems = ast ;
337280
338- if ( order === 'call-function' ) {
339- // We need to special-case `call-function` since it needs to access variables of this
340- // class.
341- return this . setup_user_function_call ( ast ) ;
342- } else if ( order === 'include' ) {
343- // We need to special-case `include` since it needs to parse a new file when called.
344- return this . setup_include ( ) ;
345- } else if ( ! Object . prototype . hasOwnProperty . call ( ORDERS , order ) ) {
281+ if ( ! Object . prototype . hasOwnProperty . call ( ORDERS , order ) ) {
346282 return { 'error' : `Unknown command "${ order } "` , 'line' : this . get_current_command_line ( ) } ;
347283 }
348284 if ( this . firstGotoParsed === false ) {
@@ -367,10 +303,15 @@ class ParserWithContext {
367303 if ( res . error !== undefined ) {
368304 res . line = this . get_current_command_line ( ) ;
369305 if ( this . elems . length !== 0 ) {
370- res . error += ` (from command \`${ this . elems [ 0 ] . getErrorText ( ) } \`)` ;
306+ res . error += ` (from command \`${ order } : ${ this . elems [ 0 ] . getErrorText ( ) } \`)` ;
371307 }
372308 return res ;
373309 }
310+ if ( res . skipInstructions ) {
311+ // We disable the `increasePos` in the context to prevent it to be done twice.
312+ return this . get_next_command ( pages , false ) ;
313+ }
314+
374315 return {
375316 'fatal_error' : FATAL_ERROR_COMMANDS . indexOf ( order ) !== - 1 ,
376317 'wait' : res [ 'wait' ] ,
@@ -380,13 +321,18 @@ class ParserWithContext {
380321 'instructions' : res [ 'instructions' ] ,
381322 'infos' : res [ 'infos' ] ,
382323 'warnings' : res [ 'warnings' ] ,
324+ 'callback' : res [ 'callback' ] ,
325+ 'noPosIncrease' : res [ 'noPosIncrease' ] ,
383326 } ;
384327 }
385328
386- get_next_command ( increasePos = true ) {
329+ get_next_command ( pages , increasePos = true ) {
387330 let context = this . get_current_context ( ) ;
388331 while ( context !== null && context . currentCommand >= context . commands . length ) {
389- this . contexts . pop ( ) ;
332+ const prevContext = this . contexts . pop ( ) ;
333+ if ( prevContext . dropCallback !== undefined ) {
334+ prevContext . dropCallback ( pages ) ;
335+ }
390336 context = this . get_current_context ( ) ;
391337 if ( context !== null ) {
392338 context . currentCommand += 1 ;
@@ -404,8 +350,8 @@ class ParserWithContext {
404350 'errors' : inferred . errors ,
405351 } ;
406352 }
407- const ret = this . run_order ( command . commandName , inferred . ast ) ;
408- if ( increasePos ) {
353+ const ret = this . run_order ( pages , command . commandName , inferred . ast ) ;
354+ if ( increasePos && ! ret [ 'noPosIncrease' ] ) {
409355 this . increase_context_pos ( ) ;
410356 }
411357 return ret ;
0 commit comments