diff --git a/js/xpconnect/shell/xpcshell.cpp b/js/xpconnect/shell/xpcshell.cpp index 5a3b51a3021..6f51ab65707 100644 --- a/js/xpconnect/shell/xpcshell.cpp +++ b/js/xpconnect/shell/xpcshell.cpp @@ -791,6 +791,24 @@ Parent(JSContext *cx, unsigned argc, jsval *vp) return true; } +static JSBool +Atob(JSContext *cx, unsigned argc, jsval *vp) +{ + if (!argc) + return true; + + return xpc::Base64Decode(cx, JS_ARGV(cx, vp)[0], &JS_RVAL(cx, vp)); +} + +static JSBool +Btoa(JSContext *cx, unsigned argc, jsval *vp) +{ + if (!argc) + return true; + + return xpc::Base64Encode(cx, JS_ARGV(cx, vp)[0], &JS_RVAL(cx, vp)); +} + static JSFunctionSpec glob_functions[] = { JS_FS("print", Print, 0,0), JS_FS("readline", ReadLine, 1,0), @@ -805,12 +823,14 @@ static JSFunctionSpec glob_functions[] = { JS_FS("gczeal", GCZeal, 1,0), #endif JS_FS("options", Options, 0,0), - JS_FN("parent", Parent, 1,0), + JS_FN("parent", Parent, 1,0), #ifdef DEBUG JS_FS("dumpHeap", DumpHeap, 5,0), #endif JS_FS("sendCommand", SendCommand, 1,0), JS_FS("getChildGlobalObject", GetChildGlobalObject, 0,0), + JS_FS("atob", Atob, 1,0), + JS_FS("btoa", Btoa, 1,0), JS_FS_END }; diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index 8303602f86a..912dca77f87 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -2322,7 +2322,7 @@ DeferredRelease(nsISupports *obj) return nsXPConnect::GetRuntimeInstance()->DeferredRelease(obj); } -bool +NS_EXPORT_(bool) Base64Encode(JSContext *cx, JS::Value val, JS::Value *out) { MOZ_ASSERT(cx); @@ -2348,7 +2348,7 @@ Base64Encode(JSContext *cx, JS::Value val, JS::Value *out) return true; } -bool +NS_EXPORT_(bool) Base64Decode(JSContext *cx, JS::Value val, JS::Value *out) { MOZ_ASSERT(cx); diff --git a/js/xpconnect/src/xpcpublic.h b/js/xpconnect/src/xpcpublic.h index 0ae0cbab7c4..3cf242117e7 100644 --- a/js/xpconnect/src/xpcpublic.h +++ b/js/xpconnect/src/xpcpublic.h @@ -214,8 +214,8 @@ namespace xpc { bool DeferredRelease(nsISupports *obj); // If these functions return false, then an exception will be set on cx. -bool Base64Encode(JSContext *cx, JS::Value val, JS::Value *out); -bool Base64Decode(JSContext *cx, JS::Value val, JS::Value *out); +NS_EXPORT_(bool) Base64Encode(JSContext *cx, JS::Value val, JS::Value *out); +NS_EXPORT_(bool) Base64Decode(JSContext *cx, JS::Value val, JS::Value *out); /** * Convert an nsString to jsval, returning true on success.