54 |
#include "jsapi.h" |
#include "jsapi.h" |
55 |
#include "jsarray.h" |
#include "jsarray.h" |
56 |
#include "jsatom.h" |
#include "jsatom.h" |
57 |
|
#include "jsbuiltins.h" |
58 |
#include "jscntxt.h" |
#include "jscntxt.h" |
59 |
#include "jsdbgapi.h" |
#include "jsdbgapi.h" |
60 |
#include "jsemit.h" |
#include "jsemit.h" |
760 |
return JS_TRUE; |
return JS_TRUE; |
761 |
} |
} |
762 |
|
|
763 |
|
#ifdef JS_TRACER |
764 |
|
static jsval JS_FASTCALL |
765 |
|
Print_tn(JSContext *cx, JSString *str) |
766 |
|
{ |
767 |
|
char *bytes = JS_EncodeString(cx, str); |
768 |
|
if (!bytes) |
769 |
|
return JSVAL_ERROR_COOKIE; |
770 |
|
fprintf(gOutFile, "%s\n", bytes); |
771 |
|
JS_free(cx, bytes); |
772 |
|
fflush(gOutFile); |
773 |
|
return JSVAL_VOID; |
774 |
|
} |
775 |
|
#endif |
776 |
|
|
777 |
static JSBool |
static JSBool |
778 |
Print(JSContext *cx, uintN argc, jsval *vp) |
Print(JSContext *cx, uintN argc, jsval *vp) |
779 |
{ |
{ |
1365 |
return JS_TRUE; |
return JS_TRUE; |
1366 |
} |
} |
1367 |
|
|
1368 |
JS_STATIC_ASSERT(JSTN_CATCH == 0); |
JS_STATIC_ASSERT(JSTRY_CATCH == 0); |
1369 |
JS_STATIC_ASSERT(JSTN_FINALLY == 1); |
JS_STATIC_ASSERT(JSTRY_FINALLY == 1); |
1370 |
JS_STATIC_ASSERT(JSTN_ITER == 2); |
JS_STATIC_ASSERT(JSTRY_ITER == 2); |
1371 |
|
|
1372 |
static const char* const TryNoteNames[] = { "catch", "finally", "iter" }; |
static const char* const TryNoteNames[] = { "catch", "finally", "iter" }; |
1373 |
|
|
2555 |
return ok; |
return ok; |
2556 |
} |
} |
2557 |
|
|
2558 |
|
static int32 JS_FASTCALL |
2559 |
|
ShapeOf_tn(JSObject *obj) |
2560 |
|
{ |
2561 |
|
if (!obj) |
2562 |
|
return 0; |
2563 |
|
if (!OBJ_IS_NATIVE(obj)) |
2564 |
|
return -1; |
2565 |
|
return OBJ_SHAPE(obj); |
2566 |
|
} |
2567 |
|
|
2568 |
|
static JSBool |
2569 |
|
ShapeOf(JSContext *cx, uintN argc, jsval *vp) |
2570 |
|
{ |
2571 |
|
jsval v = JS_ARGV(cx, vp)[0]; |
2572 |
|
if (!JSVAL_IS_OBJECT(v)) { |
2573 |
|
JS_ReportError(cx, "shapeOf: object expected"); |
2574 |
|
return JS_FALSE; |
2575 |
|
} |
2576 |
|
return JS_NewNumberValue(cx, ShapeOf_tn(JSVAL_TO_OBJECT(v)), vp); |
2577 |
|
} |
2578 |
|
|
2579 |
#ifdef JS_THREADSAFE |
#ifdef JS_THREADSAFE |
2580 |
|
|
2581 |
static JSBool |
static JSBool |
2582 |
Sleep(JSContext *cx, uintN argc, jsval *vp) |
Sleep_fn(JSContext *cx, uintN argc, jsval *vp) |
2583 |
{ |
{ |
2584 |
jsdouble t_secs; |
jsdouble t_secs; |
2585 |
PRUint32 t_ticks; |
PRUint32 t_ticks; |
2839 |
|
|
2840 |
#endif |
#endif |
2841 |
|
|
2842 |
|
JS_DEFINE_TRCINFO_1(Print, (2, (static, JSVAL_FAIL, Print_tn, CONTEXT, STRING, 0, 0))) |
2843 |
|
JS_DEFINE_TRCINFO_1(ShapeOf, (1, (static, INT32, ShapeOf_tn, OBJECT, 0, 0))) |
2844 |
|
|
2845 |
/* We use a mix of JS_FS and JS_FN to test both kinds of natives. */ |
/* We use a mix of JS_FS and JS_FN to test both kinds of natives. */ |
2846 |
static JSFunctionSpec shell_functions[] = { |
static JSFunctionSpec shell_functions[] = { |
2847 |
JS_FS("version", Version, 0,0,0), |
JS_FS("version", Version, 0,0,0), |
2848 |
JS_FS("options", Options, 0,0,0), |
JS_FS("options", Options, 0,0,0), |
2849 |
JS_FS("load", Load, 1,0,0), |
JS_FS("load", Load, 1,0,0), |
2850 |
JS_FN("readline", ReadLine, 0,0), |
JS_FN("readline", ReadLine, 0,0), |
2851 |
JS_FN("print", Print, 0,0), |
JS_TN("print", Print, 0,0, Print_trcinfo), |
2852 |
JS_FS("help", Help, 0,0,0), |
JS_FS("help", Help, 0,0,0), |
2853 |
JS_FS("quit", Quit, 0,0,0), |
JS_FS("quit", Quit, 0,0,0), |
2854 |
JS_FN("gc", GC, 0,0), |
JS_FN("gc", GC, 0,0), |
2886 |
JS_FN("getslx", GetSLX, 1,0), |
JS_FN("getslx", GetSLX, 1,0), |
2887 |
JS_FN("toint32", ToInt32, 1,0), |
JS_FN("toint32", ToInt32, 1,0), |
2888 |
JS_FS("evalcx", EvalInContext, 1,0,0), |
JS_FS("evalcx", EvalInContext, 1,0,0), |
2889 |
|
JS_TN("shapeOf", ShapeOf, 1,0, ShapeOf_trcinfo), |
2890 |
#ifdef MOZ_SHARK |
#ifdef MOZ_SHARK |
2891 |
JS_FS("startShark", js_StartShark, 0,0,0), |
JS_FS("startShark", js_StartShark, 0,0,0), |
2892 |
JS_FS("stopShark", js_StopShark, 0,0,0), |
JS_FS("stopShark", js_StopShark, 0,0,0), |
2908 |
JS_FS("arrayInfo", js_ArrayInfo, 1,0,0), |
JS_FS("arrayInfo", js_ArrayInfo, 1,0,0), |
2909 |
#endif |
#endif |
2910 |
#ifdef JS_THREADSAFE |
#ifdef JS_THREADSAFE |
2911 |
JS_FN("sleep", Sleep, 1,0), |
JS_FN("sleep", Sleep_fn, 1,0), |
2912 |
JS_FN("scatter", Scatter, 1,0), |
JS_FN("scatter", Scatter, 1,0), |
2913 |
#endif |
#endif |
2914 |
JS_FS_END |
JS_FS_END |
2971 |
" Evaluate s in optional sandbox object o\n" |
" Evaluate s in optional sandbox object o\n" |
2972 |
" if (s == '' && !o) return new o with eager standard classes\n" |
" if (s == '' && !o) return new o with eager standard classes\n" |
2973 |
" if (s == 'lazy' && !o) return new o with lazy standard classes", |
" if (s == 'lazy' && !o) return new o with lazy standard classes", |
2974 |
|
"shapeOf(obj) Get the shape of obj (an implementation detail)", |
2975 |
#ifdef MOZ_SHARK |
#ifdef MOZ_SHARK |
2976 |
"startShark() Start a Shark session.\n" |
"startShark() Start a Shark session.\n" |
2977 |
" Shark must be running with programatic sampling.", |
" Shark must be running with programatic sampling.", |
3797 |
|
|
3798 |
/* Else, we were given a real pathname, return that + the leaf. */ |
/* Else, we were given a real pathname, return that + the leaf. */ |
3799 |
dirlen = slash - from + 1; |
dirlen = slash - from + 1; |
3800 |
dir = JS_malloc(cx, dirlen + strlen(leaf) + 1); |
dir = (char*) JS_malloc(cx, dirlen + strlen(leaf) + 1); |
3801 |
if (!dir) |
if (!dir) |
3802 |
return NULL; |
return NULL; |
3803 |
|
|
3845 |
if (len == -1 || fseek(file, 0, SEEK_SET) == EOF) { |
if (len == -1 || fseek(file, 0, SEEK_SET) == EOF) { |
3846 |
JS_ReportError(cx, "can't seek start of %s", pathname); |
JS_ReportError(cx, "can't seek start of %s", pathname); |
3847 |
} else { |
} else { |
3848 |
buf = JS_malloc(cx, len + 1); |
buf = (char*) JS_malloc(cx, len + 1); |
3849 |
if (buf) { |
if (buf) { |
3850 |
cc = fread(buf, 1, len, file); |
cc = fread(buf, 1, len, file); |
3851 |
if (cc != len) { |
if (cc != len) { |