forked from Touffy/JSSCxml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SCxmlDatamodel.js
90 lines (77 loc) · 2.83 KB
/
SCxmlDatamodel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
SCxml.prototype.initIframe=function (data)
{
if(this.datamodel) return;
with(this._iframe_=document.createElement("iframe")){
className="scxml_script_frame"
style.display="none"
}
document.body.appendChild(this._iframe_)
this.datamodel=this._iframe_.contentWindow
with(this.datamodel.document)
{
open()
write('<script>\n'
+ 'function expr(s,el)\n{\n'
+ ' try{ with(_jsscxml_predefined_){ return eval(s) } }\n'
+ ' catch(e){ _sc.error("execution",el,e) }\n'
+ '}\n'
+ 'function syntexpr(s,el)\n{\n'
+ ' try{ with(_jsscxml_predefined_){ return eval(s) } }\n'
+ ' catch(e){ if(e instanceof SyntaxError) return e\n'
+ ' else _sc.error("execution",el,e) }\n'
+ '}\n'
+ 'function call(f, args)\n{\n'
+ ' try{ with(_jsscxml_predefined_){ return f.call(null, args) } }\n'
+ ' catch(e){ _sc.error("execution",f,e) }\n'
+ '}\n'
+'\n</script>\n')
}
this.datamodel._sc=this
// shadow all predefined variables
this.datamodel._jsscxml_predefined_={}
for(var i in this.datamodel) if(this.datamodel.hasOwnProperty(i))
this.datamodel._jsscxml_predefined_[i]=undefined
with(this){
datamodel.__defineGetter__("_sessionid", function(){return sid})
datamodel.__defineSetter__("_sessionid", function(){return sid})
datamodel.__defineGetter__("_event", function(){return lastEvent})
datamodel.__defineSetter__("_event", function(){return lastEvent})
datamodel.__defineGetter__("_name", function(){return name})
datamodel.__defineSetter__("_name", function(){return name})
}
this.datamodel.__defineGetter__("_ioprocessors", function(){
return SCxml.EventProcessors })
this.datamodel.__defineSetter__("_ioprocessors", function(){
return SCxml.EventProcessors })
this.datamodel._x={
voices: ("speechSynthesis" in window) && speechSynthesis.getVoices()
}
if(data) for(i in data) if(data.hasOwnProperty(i))
{
if(this.datamodel.hasOwnProperty(i))
this.datamodel._jsscxml_predefined_[i]=data[i]
else this.datamodel[i]=data[i]
}
this.datamodel.document.write('<script>\n'
+'function In(state){ return state in _sc.configuration }\n'
+'function setTimeout(){\n'
+' return _sc.timeout(arguments)\n}\n'
+'function setInterval(){\n'
+' return _sc.interval(arguments)\n}\n'
+'function clearTimeout(t){\n'
+' return t.cancel()\n}\n'
+'function clearInterval(t){\n'
+' return t.cancel()\n}\n'
+'</script>\n')
delete this.datamodel._jsscxml_predefined_.setTimeout
delete this.datamodel._jsscxml_predefined_.setInterval
delete this.datamodel._jsscxml_predefined_.clearTimeout
delete this.datamodel._jsscxml_predefined_.clearInterval
}
SCxml.prototype.wrapScript=function (script, element)
{
this.datamodel._element=element
this.datamodel.document.write('<script>\n'
+ 'try{ with(_jsscxml_predefined_){\n' + script
+ '\n}} catch(err){_sc.error("execution", _element, err)}\n</script>')
}