Beispiel #1
0
static JSBool
HandleData(JSContext *cx, JSONParser *jp, JSONDataType type, const jschar *buf, uint32 len)
{
  JSBool ok = JS_FALSE;
 
  switch (type) {
    case JSON_DATA_STRING:
      ok = HandleString(cx, jp, buf, len);
      break;
 
    case JSON_DATA_KEYSTRING:
      jp->objectKey = JS_NewUCStringCopyN(cx, buf, len);
      ok = JS_TRUE;
      break;
 
    case JSON_DATA_NUMBER:
      ok = HandleNumber(cx, jp, buf, len);
      break;
 
    case JSON_DATA_KEYWORD:
      ok = HandleKeyword(cx, jp, buf, len);
      break;
 
    default:
      JS_NOT_REACHED("Should have a JSON data type");
  }
 
  js_FinishStringBuffer(jp->buffer);
  js_InitStringBuffer(jp->buffer);
 
  return ok;
}
Beispiel #2
0
static JSBool
HandleData(JSContext *cx, JSONParser *jp, JSONDataType type)
{
  JSBool ok = JS_FALSE;

  if (!STRING_BUFFER_OK(jp->buffer))
      return JS_FALSE;

  switch (type) {
    case JSON_DATA_STRING:
      ok = HandleString(cx, jp, jp->buffer->base, STRING_BUFFER_OFFSET(jp->buffer));
      break;

    case JSON_DATA_KEYSTRING:
      js_AppendUCString(jp->objectKey, jp->buffer->base, STRING_BUFFER_OFFSET(jp->buffer));
      ok = STRING_BUFFER_OK(jp->objectKey);
      break;

    case JSON_DATA_NUMBER:
      ok = HandleNumber(cx, jp, jp->buffer->base, STRING_BUFFER_OFFSET(jp->buffer));
      break;

    case JSON_DATA_KEYWORD:
      ok = HandleKeyword(cx, jp, jp->buffer->base, STRING_BUFFER_OFFSET(jp->buffer));
      break;

    default:
      JS_NOT_REACHED("Should have a JSON data type");
  }

  js_FinishStringBuffer(jp->buffer);
  js_InitStringBuffer(jp->buffer);

  return ok;
}
Beispiel #3
0
JSBool
js_FinishJSONParse(JSContext *cx, JSONParser *jp)
{
    if (!jp)
        return JS_TRUE;

    if (jp->objectKey)
        js_FinishStringBuffer(jp->objectKey);
    JS_free(cx, jp->objectKey);

    if (jp->buffer)
        js_FinishStringBuffer(jp->buffer);
    JS_free(cx, jp->buffer);
    
    if (!js_RemoveRoot(cx->runtime, &jp->objectStack))
        return JS_FALSE;
    JSBool ok = *jp->statep == JSON_PARSE_STATE_FINISHED;
    JS_free(cx, jp);

    return ok;
}
Beispiel #4
0
static JSBool
PushValue(JSContext *cx, JSONParser *jp, JSObject *parent, jsval value)
{
    JSAutoTempValueRooter tvr(cx, 1, &value);
 
    JSBool ok;
    if (OBJ_IS_ARRAY(cx, parent)) {
        jsuint len;
        ok = js_GetLengthProperty(cx, parent, &len);
        if (ok) {
            ok = OBJ_DEFINE_PROPERTY(cx, parent, INT_TO_JSID(len), value,
                                     NULL, NULL, JSPROP_ENUMERATE, NULL);
        }
    } else {
        ok = JS_DefineUCProperty(cx, parent, jp->objectKey->base,
                                 STRING_BUFFER_OFFSET(jp->objectKey), value,
                                 NULL, NULL, JSPROP_ENUMERATE);
        js_FinishStringBuffer(jp->objectKey);
        js_InitStringBuffer(jp->objectKey);
    }

    return ok;
}