Ejemplo n.º 1
0
FRAGMENT(JSString, simple) {
  js::Rooted<JSString *> empty(cx, JS_NewStringCopyN(cx, NULL, 0));
  js::Rooted<JSString *> x(cx, JS_NewStringCopyN(cx, "x", 1));
  js::Rooted<JSString *> z(cx, JS_NewStringCopyZ(cx, "z"));

  // I expect this will be a non-inlined string.
  js::Rooted<JSString *> stars(cx, JS_NewStringCopyZ(cx,
                                                     "*************************"
                                                     "*************************"
                                                     "*************************"
                                                     "*************************"));

  // This may well be an inlined string.
  js::Rooted<JSString *> xz(cx, JS_ConcatStrings(cx, x, z));

  // This will probably be a rope.
  js::Rooted<JSString *> doubleStars(cx, JS_ConcatStrings(cx, stars, stars));

  breakpoint();

  (void) empty;
  (void) x;
  (void) z;
  (void) stars;
  (void) xz;
  (void) doubleStars;
}
Ejemplo n.º 2
0
JSBool
Output_writeLine (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
    JS_BeginRequest(cx);
    JS_EnterLocalRootScope(cx);

    JSString* string;
    JSString* endLine = JS_NewStringCopyZ(cx, "\n");

    if (argc < 1 || !JS_ConvertArguments(cx, argc, argv, "S", &string)) {
        JS_ReportError(cx, "Not enough parameters.");
        JS_LeaveLocalRootScope(cx);
        JS_EndRequest(cx);
        return JS_FALSE;
    }

    jsval property;

    string = JS_ConcatStrings(cx, string, endLine);
    JS_GetProperty(cx, obj, "content", &property);
    property = STRING_TO_JSVAL(JS_ConcatStrings(cx, JS_ValueToString(cx, property), string));
    JS_SetProperty(cx, obj, "content", &property);

    JS_LeaveLocalRootScope(cx);
    JS_EndRequest(cx);

    return JS_TRUE;
}
Ejemplo n.º 3
0
FRAGMENT(JSString, simple) {
  AutoSuppressHazardsForTest noanalysis;

  JS::Rooted<JSString*> empty(cx, JS_NewStringCopyN(cx, nullptr, 0));
  JS::Rooted<JSString*> x(cx, JS_NewStringCopyN(cx, "x", 1));
  JS::Rooted<JSString*> z(cx, JS_NewStringCopyZ(cx, "z"));

  // I expect this will be a non-inlined string.
  JS::Rooted<JSString*> stars(cx,
                              JS_NewStringCopyZ(cx,
                                                "*************************"
                                                "*************************"
                                                "*************************"
                                                "*************************"));

  // This may well be an inlined string.
  JS::Rooted<JSString*> xz(cx, JS_ConcatStrings(cx, x, z));

  // This will probably be a rope.
  JS::Rooted<JSString*> doubleStars(cx, JS_ConcatStrings(cx, stars, stars));

  // Ensure we're not confused by typedefs for pointer types.
  JSString* xRaw = x;

  breakpoint();

  use(empty);
  use(x);
  use(z);
  use(stars);
  use(xz);
  use(doubleStars);
  use(xRaw);
}
Ejemplo n.º 4
0
static void
try_to_chain_stack_trace(JSContext *src_context, JSContext *dst_context,
                         jsval src_exc) {
    /* append current stack of dst_context to stack trace for src_exc.
     * we bail if anything goes wrong, just using the src_exc unmodified
     * in that case. */
    jsval chained, src_stack, dst_stack, new_stack;
    JSString *new_stack_str;

    JS_BeginRequest(src_context);
    JS_BeginRequest(dst_context);

    if (!JSVAL_IS_OBJECT(src_exc))
        goto out; // src_exc doesn't have a stack trace

    /* create a new exception in dst_context to get a stack trace */
    gjs_throw_literal(dst_context, "Chained exception");
    if (!(JS_GetPendingException(dst_context, &chained) &&
          JSVAL_IS_OBJECT(chained)))
        goto out; // gjs_throw_literal didn't work?!
    JS_ClearPendingException(dst_context);

    /* get stack trace for src_exc and chained */
    if (!(gjs_object_get_property(dst_context, JSVAL_TO_OBJECT(chained),
                                  "stack", &dst_stack) &&
          JSVAL_IS_STRING(dst_stack)))
        goto out; // couldn't get chained stack
    if (!(gjs_object_get_property(src_context, JSVAL_TO_OBJECT(src_exc),
                                  "stack", &src_stack) &&
          JSVAL_IS_STRING(src_stack)))
        goto out; // couldn't get source stack

    /* add chained exception's stack trace to src_exc */
    new_stack_str = JS_ConcatStrings
        (dst_context, JSVAL_TO_STRING(src_stack), JSVAL_TO_STRING(dst_stack));
    if (new_stack_str==NULL)
        goto out; // couldn't concatenate src and dst stacks?!
    new_stack = STRING_TO_JSVAL(new_stack_str);
    JS_SetProperty(dst_context, JSVAL_TO_OBJECT(src_exc), "stack", &new_stack);

 out:
    JS_EndRequest(dst_context);
    JS_EndRequest(src_context);
}