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