Skip to content

Instantly share code, notes, and snippets.

@sdwilsh
Created May 9, 2011 20:00
Show Gist options
  • Save sdwilsh/963265 to your computer and use it in GitHub Desktop.
Save sdwilsh/963265 to your computer and use it in GitHub Desktop.
JS API test file for possible Typed Arrays Bug
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=4 sw=4 et tw=99:
*/
#include "tests.h"
#include "jsobj.h"
BEGIN_TEST(testPrototypeLookup)
{
jsval arrVal;
EVAL("new Uint8Array(new ArrayBuffer(10))", &arrVal);
JSObject* obj = JSVAL_TO_OBJECT(arrVal);
CHECK(JS_SetProperty(cx, global, "arr", &arrVal));
JSObject* newProto = JS_NewObject(cx, NULL, NULL, JS_GetParent(cx, obj));
CHECK(newProto);
jsval tp = INT_TO_JSVAL(42);
CHECK(JS_SetProperty(cx, newProto, "testprop", &tp));
JSObject* ref = JS_GetPrototype(cx, obj);
js_DumpObject(ref);
CHECK(JS_SetPrototype(cx, ref, newProto));
CHECK(newProto == JS_GetPrototype(cx, ref));
jsval lookup;
CHECK(JS_GetProperty(cx, obj, "testprop", &lookup));
CHECK(JSVAL_TO_INT(lookup) == 42);
jsval jsLookup;
EVAL("arr.testprop", &jsLookup);
CHECK(JSVAL_TO_INT(jsLookup) == 42);
return true;
}
END_TEST(testPrototypeLookup)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment