src/jdk/nashorn/internal/objects/NativeError.java

Print this page




 310 
 311     /**
 312      * Nashorn extension: Error.prototype.stack
 313      * "stack" property is a string typed value containing JavaScript stack frames.
 314      * Each frame information is separated bv "\n" character.
 315      *
 316      * @param self  self reference
 317      *
 318      * @return      value of "stack" property
 319      */
 320     public static Object getStack(final Object self) {
 321         Global.checkObject(self);
 322         final ScriptObject sobj = (ScriptObject)self;
 323         if (sobj.has(STACK)) {
 324             return sobj.get(STACK);
 325         }
 326 
 327         final Object exception = ECMAException.getException(sobj);
 328         if (exception instanceof Throwable) {
 329             Object value = getScriptStackString(sobj, (Throwable)exception);

 330             sobj.put(STACK, value, false);




 331             return value;
 332         }
 333 
 334         return UNDEFINED;
 335     }
 336 
 337     /**
 338      * Nashorn extension
 339      * Accessed from {@link Global} while setting up the Error.prototype
 340      *
 341      * @param self   self reference
 342      * @param value  value to set "stack" property to, must be {@code ScriptObject}
 343      *
 344      * @return value that was set
 345      */
 346     public static Object setStack(final Object self, final Object value) {
 347         Global.checkObject(self);
 348         final ScriptObject sobj = (ScriptObject)self;
 349         sobj.set(STACK, value, false);





 350         return value;
 351     }
 352 
 353     /**
 354      * ECMA 15.11.4.4 Error.prototype.toString ( )
 355      *
 356      * @param self  self reference
 357      *
 358      * @return this NativeError as a string
 359      */
 360     @Function(attributes = Attribute.NOT_ENUMERABLE)
 361     public static Object toString(final Object self) {
 362         // Step 1 and 2 : check if 'self' is object it not throw TypeError
 363         Global.checkObject(self);
 364 
 365         final ScriptObject sobj = (ScriptObject)self;
 366 
 367         // Step 3 & 4 : get "name" and convert to String.
 368         // But if message is undefined make it "Error".
 369         Object name = sobj.get("name");




 310 
 311     /**
 312      * Nashorn extension: Error.prototype.stack
 313      * "stack" property is a string typed value containing JavaScript stack frames.
 314      * Each frame information is separated bv "\n" character.
 315      *
 316      * @param self  self reference
 317      *
 318      * @return      value of "stack" property
 319      */
 320     public static Object getStack(final Object self) {
 321         Global.checkObject(self);
 322         final ScriptObject sobj = (ScriptObject)self;
 323         if (sobj.has(STACK)) {
 324             return sobj.get(STACK);
 325         }
 326 
 327         final Object exception = ECMAException.getException(sobj);
 328         if (exception instanceof Throwable) {
 329             Object value = getScriptStackString(sobj, (Throwable)exception);
 330             if (sobj.hasOwnProperty(STACK)) {
 331                 sobj.put(STACK, value, false);
 332             } else {
 333                 sobj.addOwnProperty(STACK, Attribute.NOT_ENUMERABLE, value);
 334             }
 335 
 336             return value;
 337         }
 338 
 339         return UNDEFINED;
 340     }
 341 
 342     /**
 343      * Nashorn extension
 344      * Accessed from {@link Global} while setting up the Error.prototype
 345      *
 346      * @param self   self reference
 347      * @param value  value to set "stack" property to, must be {@code ScriptObject}
 348      *
 349      * @return value that was set
 350      */
 351     public static Object setStack(final Object self, final Object value) {
 352         Global.checkObject(self);
 353         final ScriptObject sobj = (ScriptObject)self;
 354         if (sobj.hasOwnProperty(STACK)) {
 355             sobj.put(STACK, value, false);
 356         } else {
 357             sobj.addOwnProperty(STACK, Attribute.NOT_ENUMERABLE, value);
 358         }
 359 
 360         return value;
 361     }
 362 
 363     /**
 364      * ECMA 15.11.4.4 Error.prototype.toString ( )
 365      *
 366      * @param self  self reference
 367      *
 368      * @return this NativeError as a string
 369      */
 370     @Function(attributes = Attribute.NOT_ENUMERABLE)
 371     public static Object toString(final Object self) {
 372         // Step 1 and 2 : check if 'self' is object it not throw TypeError
 373         Global.checkObject(self);
 374 
 375         final ScriptObject sobj = (ScriptObject)self;
 376 
 377         // Step 3 & 4 : get "name" and convert to String.
 378         // But if message is undefined make it "Error".
 379         Object name = sobj.get("name");