@@ -47,6 +47,9 @@ module Runtime {
4747 private _listeners :{ [ name :string ] : Array < Function > } = { } ;
4848
4949 constructor ( name :string ) {
50+ if ( name . slice ( 0 , 2 ) !== '__' ) {
51+ throw new Error ( 'MetaObject names must start with two underscores.' ) ;
52+ }
5053 this . _name = name ;
5154 }
5255
@@ -103,6 +106,7 @@ module Runtime {
103106 }
104107
105108 /** Variables **/
109+ // objCount is uniformly increasing to make object names unique
106110 var objCount :number = 0 ;
107111 var _registeredObjects :ObjectRegistry = {
108112 '__self' : new MetaObject ( '__self' ) ,
@@ -149,9 +153,9 @@ module Runtime {
149153 /**
150154 * Gets the object registered by id
151155 * @param {string } objectId - objectid of object
152- * @returns {any } - object or undefined if not found
156+ * @returns {RegisterableObject } - object or undefined if not found
153157 */
154- export function getObject ( objectId :string ) :any {
158+ export function getObject ( objectId :string ) :RegisterableObject {
155159 return _registeredObjects [ objectId ] ;
156160 }
157161
@@ -162,25 +166,26 @@ module Runtime {
162166 */
163167 export function registerObject ( object :RegisterableObject ) :void {
164168 if ( ! object . getId ) {
165- __trace ( "Attempted to register unnamed object" , " warn" ) ;
169+ __trace ( 'Cannot register object without getId method.' , ' warn' ) ;
166170 return ;
167171 }
168172 if ( ! Runtime . hasObject ( object . getId ( ) ) ) {
169173 _registeredObjects [ object . getId ( ) ] = object ;
170- __pchannel ( " Runtime:RegisterObject" , {
171- "id" : object . getId ( ) ,
172- " data" : object . serialize ( )
174+ __pchannel ( ' Runtime:RegisterObject' , {
175+ 'id' : object . getId ( ) ,
176+ ' data' : object . serialize ( )
173177 } ) ;
174178 __schannel ( "object::(" + object . getId ( ) + ")" , ( payload :any ) => {
175- if ( payload . hasOwnProperty ( " type" ) &&
176- payload . type === " event" ) {
179+ if ( payload . hasOwnProperty ( ' type' ) &&
180+ payload . type === ' event' ) {
177181 _dispatchEvent ( object . getId ( ) , payload . event , payload . data ) ;
178182 }
179183 } ) ;
180184 objCount ++ ;
181185 return ;
182186 } else {
183- __trace ( 'Attempted to re-register object or id collision' , 'warn' ) ;
187+ __trace ( 'Attempted to re-register object or id collision @ ' +
188+ object . getId ( ) , 'warn' ) ;
184189 return ;
185190 }
186191 }
@@ -194,33 +199,39 @@ module Runtime {
194199 */
195200 export function deregisterObject ( objectId :string ) :void {
196201 if ( Runtime . hasObject ( objectId ) ) {
197- if ( objectId . substr ( 0 , 2 ) === "__" ) {
198- __trace ( "Runtime.deregisterObject cannot de-register a MetaObject" , "warn" ) ;
202+ if ( objectId . substr ( 0 , 2 ) === '__' ) {
203+ __trace ( 'Runtime.deregisterObject cannot de-register a MetaObject' ,
204+ 'warn' ) ;
199205 return ;
200206 }
201- __pchannel ( " Runtime:DeregisterObject" , {
202- "id" : objectId
207+ __pchannel ( ' Runtime:DeregisterObject' , {
208+ 'id' : objectId
203209 } ) ;
204210 if ( typeof _registeredObjects [ objectId ] . unload === "function" ) {
205211 // Gracefully unload first
206212 _registeredObjects [ objectId ] . unload ( ) ;
207213 }
208214 _registeredObjects [ objectId ] = null ;
209215 delete _registeredObjects [ objectId ] ;
210- objCount -- ;
211216 }
212217 }
213218
219+ function _getId ( type :string = 'obj' , container :string = 'rt' ) :string {
220+ var randomSeed :number = Math . random ( )
221+ var randomSegment :string = '' ;
222+ return ;
223+ }
224+
214225 /**
215226 * Generates an objectid that isn't registered
216227 * @param {string } type - object type
217228 * @returns {string } - objectid that has not been registered
218229 */
219230 export function generateId ( type :string = "obj" ) :string {
220- var id :string = type + ":" + ( new Date ( ) ) . getTime ( ) + "|" +
221- Math . round ( Math . random ( ) * 4096 ) + ":" + objCount ;
231+ var id :string = [ type , ':' , Date . now ( ) , '|' ,
232+ Math . round ( Math . random ( ) * 4096 ) , ':' , objCount ] . join ( ) ;
222233 while ( Runtime . hasObject ( id ) ) {
223- id = type + ":" + ( new Date ( ) ) . getTime ( ) + "|" +
234+ id = type + ":" + Date . now ( ) + "|" +
224235 Math . round ( Math . random ( ) * 4096 ) + ":" + objCount ;
225236 }
226237 return id ;
@@ -254,7 +265,7 @@ module Runtime {
254265 }
255266
256267 /**
257- * Invoke termination of script
268+ * Invoke termination of script from outside the sandbox
258269 */
259270 export function crash ( ) :void {
260271 __trace ( "Runtime.crash() : Manual crash" , "fatal" ) ;
0 commit comments