Skip to content

Commit 1a27e1c

Browse files
committed
Fix bug in inserting await
1 parent 11af2b2 commit 1a27e1c

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

ide/ide.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ $(function () {
13641364
})
13651365

13661366
var frameSrc = run_link
1367-
var frameHTML = '<iframe style="border-style:none; border:0; width:650px; height:500px; margin:0; padding:0;" frameborder=0 src="' + frameSrc + '"></iframe>'
1367+
var frameHTML = '<iframe style="border-style:none; border:0; width:650px; height:500px; margin:0; padding:0;" allow="hid" frameborder=0 src="' + frameSrc + '"></iframe>'
13681368
page.find(".frameSource").text( frameHTML );
13691369
}
13701370
pages.downloadProgram = function(route) { // Currently the only program option is download (download a program to user computer)

lib/compiling/GScompiler.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,11 @@ where compile() was called, in untrusted/run.js.
910910
var initialstart = prog.search(lineno_string)
911911
start = initialstart
912912

913+
// console.log('fcts', fcts)
914+
// console.log('classes', classes)
915+
// console.log('classinstances', classinstances)
916+
// console.log('classmethods', classmethods)
917+
913918
// Prepend 'async ' to all user functions
914919
let filter_functions = []
915920
while (true) { // locate Python filter(name, list)
@@ -938,9 +943,10 @@ where compile() was called, in untrusted/run.js.
938943
prog = prog.slice(0,start+m.index+1)+'async function '+name+string_insert+prog.slice(start+m.index+m[0].length)
939944
start += m.index+'async function '.length+m[1].length+string_insert.length+1
940945
}
941-
} // end of prepending 'async' to user functions
942-
943-
// Prepend "await " to calls to user functions and the GlowScript async functions (all user functions and class methods are marked async).
946+
}
947+
// ===================== End of prepending 'async' to user functions =====================
948+
// Next, prepend "await " to calls to user functions and the GlowScript async functions (all user functions and class methods are marked async).
949+
944950
start = initialstart
945951

946952
// VPython_import is the prefix of VPython objects, with value 'null' if no import statement
@@ -1094,23 +1100,20 @@ where compile() was called, in untrusted/run.js.
10941100
// be difficult in the transpiling to know whether "obj" is a user object or a VPython object,
10951101
// both of which have rotate methods, but only the user object needs await.
10961102

1097-
1098-
10991103
if ( // Test for cases that need await:
11001104
(period && prefix == 'self') || // in self.f, f may be a function passed to __init__
11011105
(period && prefix.slice(0,10) == 'ρσ_getitem' && classmethods.indexOf(name) >= 0) || // ρσ_getitem(...).usermethod
11021106
(period && classes.indexOf(prefix) >= 0 && classmethods.indexOf(name) >= 0) || // userclass.usermethod()
11031107
(period && classinstances.indexOf(prefix) < 0 && vpfcts.indexOf(name) >= 0) || // scene.pause(), scene.waitfor(), scene.capture()
11041108
(period && prefix === VPython_import && vpwaits.indexOf(name) >= 0) || // vp.rate/vp.sleep/vp.get_library/vp.read_local_file
11051109
(period && classinstances.indexOf(prefix) >= 0 && classmethods.indexOf(name) >= 0) || // userinstance.usermethod()
1106-
(period && classinstances.indexOf(name) < 0 && no_await2.indexOf(name) < 0) || // scene.bind()
1110+
(period && classinstances.indexOf(prefix) >= 0 && no_await2.indexOf(name) < 0) || // scene.bind()
11071111
(!period && fcts.indexOf(name) >= 0) || // f()
11081112
(!period && classmethods.indexOf(name) >= 0) || // usermethod(), preceded by usermethod = userclass.method()
11091113
(!period && classes.indexOf(name) >= 0) || // userclass()
11101114
(!period && no_await.indexOf(name) < 0) || // cos()
11111115
(!period && no_await.indexOf(name) < 0 && no_await2.indexOf(name) < 0 &&
11121116
fcts.indexOf(name) < 0)) { // probably a user function has been passed to a function
1113-
;
11141117
} else { // probably no need to prepend await
11151118
if (period && prefix == 'ρσ_interpolate_kwargs' && name == 'call') { // ρσ_interpolate_kwargs.call(this, f, ....)
11161119
let end = prog.slice(start+m.index).search('\n')
@@ -1222,16 +1225,16 @@ where compile() was called, in untrusted/run.js.
12221225
// s = " ρσ_list_decorate.prototype.pop = function(arg) {return this.pypop(arg)}\n"
12231226
// program = program.slice(0,sc)+s+program.slice(sc,program.length)
12241227

1225-
// var p = program.split('\n')
1226-
// for (var i=0; i<p.length; i++) console.log(i, p[i])
1228+
// let p = program.split('\n')
1229+
// for (let i=0; i<p.length; i++) console.log(i, p[i])
12271230
// console.log('fcts', fcts)
12281231
// console.log('vpfcts', vpfcts)
12291232
// console.log('classes', classes)
12301233
// console.log('classinstances', classinstances)
12311234
// console.log('classmethods', classmethods)
12321235
// console.log('============================================================================')
1233-
// var i = program.search('"2";')
1234-
// var i = program.search('async function __main__')
1236+
// let i = program.search('"2";')
1237+
// let i = program.search('async function __main__')
12351238
// console.log(program.slice(i))
12361239
// console.log(program)
12371240
return program

package/RScompiler.3.2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package/compiler.3.2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)