From 37da2899f40661e3e9631e497da8dc59b971cbd0 Mon Sep 17 00:00:00 2001 From: "Charles.Forsyth" Date: Fri, 22 Dec 2006 17:07:39 +0000 Subject: 20060303a --- appl/charon/jscript.b | 3025 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 3025 insertions(+) create mode 100644 appl/charon/jscript.b (limited to 'appl/charon/jscript.b') diff --git a/appl/charon/jscript.b b/appl/charon/jscript.b new file mode 100644 index 00000000..ad35f295 --- /dev/null +++ b/appl/charon/jscript.b @@ -0,0 +1,3025 @@ +implement JScript; + +include "common.m"; +include "ecmascript.m"; + +ES: Ecmascript; + Exec, Obj, Call, Prop, Val, Ref, RefVal, Builtin, ReadOnly: import ES; +me: ESHostobj; + +# local copies from CU +sys: Sys; +CU: CharonUtils; + +D: Draw; +S: String; +T: StringIntTab; +C: Ctype; +B: Build; + Item: import B; +CH: Charon; +L: Layout; + Frame, Control: import L; +U: Url; + Parsedurl: import U; +E: Events; + Event, ScriptEvent: import E; + +G : Gui; + +JScript: module +{ + # First, conform to Script interface + defaultStatus: string; + jevchan: chan of ref ScriptEvent; + versions: array of string; + + init: fn(cu: CharonUtils): string; + frametreechanged: fn(top: ref Layout->Frame); + havenewdoc: fn(f: ref Layout->Frame); + evalscript: fn(f: ref Layout->Frame, s: string) : (string, string, string); + framedone: fn(f : ref Layout->Frame, hasscripts : int); + + # + # implement the host object interface, too + # + get: fn(ex: ref Exec, o: ref Obj, property: string): ref Val; + put: fn(ex: ref Exec, o: ref Obj, property: string, val: ref Val); + canput: fn(ex: ref Exec, o: ref Obj, property: string): ref Val; + hasproperty: fn(ex: ref Exec, o: ref Obj, property: string): ref Val; + delete: fn(ex: ref Exec, o: ref Obj, property: string); + defaultval: fn(ex: ref Exec, o: ref Obj, tyhint: int): ref Val; + call: fn(ex: ref Exec, func, this: ref Obj, args: array of ref Val, eval: int): ref Ref; + construct: fn(ex: ref Exec, func: ref Obj, args: array of ref Val): ref Obj; +}; + +versions = array [] of { + "javascript", + "javascript1.0", + "javascript1.1", + "javascript1.2", + "javascript1.3", +}; + +# Call init() before calling anything else. +# It makes a global object (a Window) for the browser's top level frame, +# and also puts a navaigator object in it. The document can't be filled +# in until the first document gets loaded. +# +# This module keeps track of the correspondence between the Script Window +# objects and the corresponding Layout Frames, using the ScriptWin adt to +# build a tree mirroring the structure. The root of the tree never changes +# after first being set (but changing its document essentially resets all of the +# other data structures). After charon has built its top-level window, it +# should call frametreechanged(top). +# +# When a frame gets reset or gets some frame children added, call frametreechanged(f), +# where f is the changed frame. This module will update its ScriptWin tree as needed. +# +# Whenever the document in a (Layout) Frame f changes, call havenewdoc(f) +# after the frame's doc field is set. This causes this module to initialize the document +# object in the corresponding window object. +# +# From within the build process, call evalscript(containing frame, script) to evaluate +# global code fragments as needed. The return value is two strings: a possible error +# description, and HTML that is the result of a document.write (so it should be spliced +# in at the point where the