@@ -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 ) {
@@ -335,14 +278,7 @@ class ParserWithContext {
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 ( false ) ;
313+ }
314+
374315 return {
375316 'fatal_error' : FATAL_ERROR_COMMANDS . indexOf ( order ) !== - 1 ,
376317 'wait' : res [ 'wait' ] ,
0 commit comments