Bug 679861 - Normalize jsvals before handing them to APIs. r=gal

This commit is contained in:
Blake Kaplan 2011-09-21 19:22:34 -07:00
Родитель b8575602ef
Коммит 71794c62bb
3 изменённых файлов: 54 добавлений и 0 удалений

Просмотреть файл

@ -885,6 +885,8 @@ static JSBool
proxy_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
JSProperty **propp)
{
id = js_CheckForStringIndex(id);
bool found;
if (!JSProxy::has(cx, obj, id, &found))
return false;
@ -913,6 +915,8 @@ static JSBool
proxy_DefineProperty(JSContext *cx, JSObject *obj, jsid id, const Value *value,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
{
id = js_CheckForStringIndex(id);
AutoPropertyDescriptorRooter desc(cx);
desc.obj = obj;
desc.value = *value;
@ -936,6 +940,8 @@ proxy_DefineElement(JSContext *cx, JSObject *obj, uint32 index, const Value *val
static JSBool
proxy_GetProperty(JSContext *cx, JSObject *obj, JSObject *receiver, jsid id, Value *vp)
{
id = js_CheckForStringIndex(id);
return JSProxy::get(cx, obj, receiver, id, vp);
}
@ -951,6 +957,8 @@ proxy_GetElement(JSContext *cx, JSObject *obj, JSObject *receiver, uint32 index,
static JSBool
proxy_SetProperty(JSContext *cx, JSObject *obj, jsid id, Value *vp, JSBool strict)
{
id = js_CheckForStringIndex(id);
return JSProxy::set(cx, obj, obj, id, strict, vp);
}
@ -966,6 +974,8 @@ proxy_SetElement(JSContext *cx, JSObject *obj, uint32 index, Value *vp, JSBool s
static JSBool
proxy_GetAttributes(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp)
{
id = js_CheckForStringIndex(id);
AutoPropertyDescriptorRooter desc(cx);
if (!JSProxy::getOwnPropertyDescriptor(cx, obj, id, false, &desc))
return false;
@ -985,6 +995,8 @@ proxy_GetElementAttributes(JSContext *cx, JSObject *obj, uint32 index, uintN *at
static JSBool
proxy_SetAttributes(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp)
{
id = js_CheckForStringIndex(id);
/* Lookup the current property descriptor so we have setter/getter/value. */
AutoPropertyDescriptorRooter desc(cx);
if (!JSProxy::getOwnPropertyDescriptor(cx, obj, id, true, &desc))
@ -1005,6 +1017,8 @@ proxy_SetElementAttributes(JSContext *cx, JSObject *obj, uint32 index, uintN *at
static JSBool
proxy_DeleteProperty(JSContext *cx, JSObject *obj, jsid id, Value *rval, JSBool strict)
{
id = js_CheckForStringIndex(id);
// TODO: throwing away strict
bool deleted;
if (!JSProxy::delete_(cx, obj, id, &deleted) || !js_SuppressDeletedProperty(cx, obj, id))

Просмотреть файл

@ -67,6 +67,7 @@ _CHROME_FILES = \
test_bug596580.xul \
test_bug654370.xul \
test_bug658560.xul \
test_bug679861.xul \
test_APIExposer.xul \
test_bug664689.xul \
test_precisegc.xul \

Просмотреть файл

@ -0,0 +1,39 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=500931
-->
<window title="Mozilla Bug 601803"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=601803"
target="_blank">Mozilla Bug 601803</a>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
/** Test for Bug 601803 **/
function go() {
var doc = document.getElementById('ifr').contentDocument;
var list = doc.getElementsByTagName("body");
var zeroAsString = "0";
is(typeof list[zeroAsString], "object",
"can lookup nodelist items by string");
is(typeof list[0], "object",
"can lookup nodelist items by integer after the lookup by string");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
]]></script>
<iframe type="content" src="about:blank" onload="go()" id="ifr" />
</body>
</window>