# HG changeset patch # User Atul Varma # Date 1245706744 25200 # Node ID cb058fac14fab65cc4071d4e3ca101a09ed0937b # Parent bda50240b295f68e5c4ab4fee2cb8210ebc8b8ba Added an enumerate() function to the TCB global. diff -r bda50240b295 -r cb058fac14fa spidermonkey-playground.cpp --- a/spidermonkey-playground.cpp Mon Jun 22 13:32:03 2009 -0700 +++ b/spidermonkey-playground.cpp Mon Jun 22 14:39:04 2009 -0700 @@ -136,6 +136,26 @@ return JS_TRUE; } +// This native JS function is a wrapper for JS_Enumerate(). + +static JSBool enumerate(JSContext *cx, JSObject *obj, uintN argc, + jsval *argv, jsval *rval) +{ + JSObject *target; + + if (!JS_ConvertArguments(cx, argc, argv, "o", &target)) + return JS_FALSE; + + JSIdArray *ids = JS_Enumerate(cx, target); + + if (ids == NULL) + return JS_FALSE; + + JSObject *array = JS_NewArrayObject(cx, ids->length, ids->vector); + *rval = OBJECT_TO_JSVAL(array); + return JS_TRUE; +} + // This native JS function looks up the property of an object, bypassing // security checks and getters/setters. @@ -347,6 +367,7 @@ JS_FS("require", require, 2, 0, 0), JS_FS("lookupProperty", lookupProperty, 2, 0, 0), JS_FS("functionInfo", functionInfo, 1, 0, 0), + JS_FS("enumerate", enumerate, 1, 0, 0), JS_FS_END };