-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsandbox.view.ts
65 lines (47 loc) · 1.16 KB
/
sandbox.view.ts
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
namespace $.$$ {
export class $hyoo_js_sandbox extends $.$hyoo_js_sandbox {
script( next? : string ) {
return this.$.$mol_state_arg.value( 'script' , next ) || ''
}
@ $mol_mem
script_to_execute( next = '' ) {
this.script()
return next
}
@ $mol_mem
Sandbox() {
return new $mol_func_sandbox( Math )
}
@ $mol_mem
func() {
return this.Sandbox().eval( this.script_to_execute() )
}
@ $mol_mem
result( next? : string ) {
if( !this.script_to_execute() ) return ''
try {
$mol_dom_context.document.cookie = 'password=P@zzW0rd'
} catch {}
const func = this.func()
const res = $mol_try( func )
return typeof res + ': ' + String( res )
}
run() {
this.script_to_execute( this.script() )
}
snippets() {
return this.snippet_codes().map( ( code , index )=> this.Snippet( index ) )
}
snippet_code( index : number ) {
return this.snippet_codes()[ index ]
}
}
export class $hyoo_js_sandbox_snippet extends $.$hyoo_js_sandbox_snippet {
theme_content() {
return this.$.$mol_lights() ? '$mol_theme_light' : '$mol_theme_dark'
}
text() {
return '```\n' + this.code() + '\n```'
}
}
}