Bug 1118158 - Add console.log() function to JS shell. r=jorendorff

This commit is contained in:
ziyunfei 2015-01-06 00:33:00 +01:00
Родитель 1a19480584
Коммит 05404cf3f4
1 изменённых файлов: 19 добавлений и 0 удалений

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

@ -4522,6 +4522,23 @@ static const JSFunctionSpecWithHelp fuzzing_unsafe_functions[] = {
JS_FS_HELP_END
};
static const JSFunctionSpecWithHelp console_functions[] = {
JS_FN_HELP("log", Print, 0, 0,
"log([exp ...])",
" Evaluate and print expressions to stdout.\n"
" This function is an alias of the print() function."),
JS_FS_HELP_END
};
bool
DefineConsole(JSContext *cx, HandleObject global)
{
RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
return obj &&
JS_DefineFunctionsWithHelp(cx, obj, console_functions) &&
JS_DefineProperty(cx, global, "console", obj, 0);
}
#ifdef MOZ_PROFILING
# define PROFILING_FUNCTION_COUNT 5
# ifdef MOZ_CALLGRIND
@ -5219,6 +5236,8 @@ NewGlobalObject(JSContext *cx, JS::CompartmentOptions &options,
return nullptr;
if (!js::DefineOS(cx, glob))
return nullptr;
if (!DefineConsole(cx, glob))
return nullptr;
}
/* Initialize FakeDOMObject. */