jbarnette-johnson 1.0.0.200806240111 → 1.0.0.200807291507
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MANIFEST +1 -0
- data/Rakefile +3 -10
- data/bin/johnson +2 -1
- data/ext/spidermonkey/context.c +3 -4
- data/ext/spidermonkey/context.h +1 -1
- data/ext/spidermonkey/conversions.c +39 -33
- data/ext/spidermonkey/debugger.c +5 -5
- data/ext/spidermonkey/immutable_node.c.erb +11 -11
- data/ext/spidermonkey/jroot.h +4 -4
- data/ext/spidermonkey/js_land_proxy.c +9 -8
- data/ext/spidermonkey/ruby_land_proxy.c +5 -4
- data/ext/spidermonkey/runtime.c +1 -1
- data/johnson.gemspec +36 -0
- data/lib/hoe.rb +0 -7
- data/lib/johnson/cli/options.rb +10 -4
- data/lib/johnson/spidermonkey/runtime.rb +2 -2
- data/lib/johnson/version.rb +4 -2
- data/lib/johnson.rb +1 -0
- data/test/johnson/runtime_test.rb +11 -0
- data/test/johnson/spidermonkey/ruby_land_proxy_test.rb +6 -0
- data/vendor/spidermonkey/.cvsignore +9 -0
- data/vendor/spidermonkey/Makefile.in +462 -0
- data/vendor/spidermonkey/Makefile.ref +364 -0
- data/vendor/spidermonkey/README.html +820 -0
- data/vendor/spidermonkey/SpiderMonkey.rsp +12 -0
- data/vendor/spidermonkey/Y.js +19 -0
- data/vendor/spidermonkey/build.mk +43 -0
- data/vendor/spidermonkey/config/AIX4.1.mk +65 -0
- data/vendor/spidermonkey/config/AIX4.2.mk +64 -0
- data/vendor/spidermonkey/config/AIX4.3.mk +65 -0
- data/vendor/spidermonkey/config/Darwin.mk +83 -0
- data/vendor/spidermonkey/config/Darwin1.3.mk +81 -0
- data/vendor/spidermonkey/config/Darwin1.4.mk +41 -0
- data/vendor/spidermonkey/config/Darwin5.2.mk +81 -0
- data/vendor/spidermonkey/config/Darwin5.3.mk +81 -0
- data/vendor/spidermonkey/config/HP-UXB.10.10.mk +77 -0
- data/vendor/spidermonkey/config/HP-UXB.10.20.mk +77 -0
- data/vendor/spidermonkey/config/HP-UXB.11.00.mk +80 -0
- data/vendor/spidermonkey/config/IRIX.mk +87 -0
- data/vendor/spidermonkey/config/IRIX5.3.mk +44 -0
- data/vendor/spidermonkey/config/IRIX6.1.mk +44 -0
- data/vendor/spidermonkey/config/IRIX6.2.mk +44 -0
- data/vendor/spidermonkey/config/IRIX6.3.mk +44 -0
- data/vendor/spidermonkey/config/IRIX6.5.mk +44 -0
- data/vendor/spidermonkey/config/Linux_All.mk +103 -0
- data/vendor/spidermonkey/config/Mac_OS10.0.mk +82 -0
- data/vendor/spidermonkey/config/OSF1V4.0.mk +72 -0
- data/vendor/spidermonkey/config/OSF1V5.0.mk +69 -0
- data/vendor/spidermonkey/config/SunOS4.1.4.mk +101 -0
- data/vendor/spidermonkey/config/SunOS5.10.mk +50 -0
- data/vendor/spidermonkey/config/SunOS5.3.mk +91 -0
- data/vendor/spidermonkey/config/SunOS5.4.mk +92 -0
- data/vendor/spidermonkey/config/SunOS5.5.1.mk +44 -0
- data/vendor/spidermonkey/config/SunOS5.5.mk +87 -0
- data/vendor/spidermonkey/config/SunOS5.6.mk +89 -0
- data/vendor/spidermonkey/config/SunOS5.7.mk +44 -0
- data/vendor/spidermonkey/config/SunOS5.8.mk +44 -0
- data/vendor/spidermonkey/config/SunOS5.9.mk +44 -0
- data/vendor/spidermonkey/config/WINNT4.0.mk +117 -0
- data/vendor/spidermonkey/config/WINNT5.0.mk +117 -0
- data/vendor/spidermonkey/config/WINNT5.1.mk +117 -0
- data/vendor/spidermonkey/config/WINNT5.2.mk +117 -0
- data/vendor/spidermonkey/config/WINNT6.0.mk +117 -0
- data/vendor/spidermonkey/config/dgux.mk +64 -0
- data/vendor/spidermonkey/config.mk +192 -0
- data/vendor/spidermonkey/editline/Makefile.ref +144 -0
- data/vendor/spidermonkey/editline/README +83 -0
- data/vendor/spidermonkey/editline/editline.3 +175 -0
- data/vendor/spidermonkey/editline/editline.c +1369 -0
- data/vendor/spidermonkey/editline/editline.h +135 -0
- data/vendor/spidermonkey/editline/sysunix.c +182 -0
- data/vendor/spidermonkey/editline/unix.h +82 -0
- data/vendor/spidermonkey/fdlibm/.cvsignore +7 -0
- data/vendor/spidermonkey/fdlibm/Makefile.in +127 -0
- data/vendor/spidermonkey/fdlibm/Makefile.ref +192 -0
- data/vendor/spidermonkey/fdlibm/e_acos.c +147 -0
- data/vendor/spidermonkey/fdlibm/e_acosh.c +105 -0
- data/vendor/spidermonkey/fdlibm/e_asin.c +156 -0
- data/vendor/spidermonkey/fdlibm/e_atan2.c +165 -0
- data/vendor/spidermonkey/fdlibm/e_atanh.c +110 -0
- data/vendor/spidermonkey/fdlibm/e_cosh.c +133 -0
- data/vendor/spidermonkey/fdlibm/e_exp.c +202 -0
- data/vendor/spidermonkey/fdlibm/e_fmod.c +184 -0
- data/vendor/spidermonkey/fdlibm/e_gamma.c +71 -0
- data/vendor/spidermonkey/fdlibm/e_gamma_r.c +70 -0
- data/vendor/spidermonkey/fdlibm/e_hypot.c +173 -0
- data/vendor/spidermonkey/fdlibm/e_j0.c +524 -0
- data/vendor/spidermonkey/fdlibm/e_j1.c +523 -0
- data/vendor/spidermonkey/fdlibm/e_jn.c +315 -0
- data/vendor/spidermonkey/fdlibm/e_lgamma.c +71 -0
- data/vendor/spidermonkey/fdlibm/e_lgamma_r.c +347 -0
- data/vendor/spidermonkey/fdlibm/e_log.c +184 -0
- data/vendor/spidermonkey/fdlibm/e_log10.c +134 -0
- data/vendor/spidermonkey/fdlibm/e_pow.c +386 -0
- data/vendor/spidermonkey/fdlibm/e_rem_pio2.c +222 -0
- data/vendor/spidermonkey/fdlibm/e_remainder.c +120 -0
- data/vendor/spidermonkey/fdlibm/e_scalb.c +89 -0
- data/vendor/spidermonkey/fdlibm/e_sinh.c +122 -0
- data/vendor/spidermonkey/fdlibm/e_sqrt.c +497 -0
- data/vendor/spidermonkey/fdlibm/fdlibm.h +273 -0
- data/vendor/spidermonkey/fdlibm/fdlibm.mak +1453 -0
- data/vendor/spidermonkey/fdlibm/fdlibm.mdp +0 -0
- data/vendor/spidermonkey/fdlibm/k_cos.c +135 -0
- data/vendor/spidermonkey/fdlibm/k_rem_pio2.c +354 -0
- data/vendor/spidermonkey/fdlibm/k_sin.c +114 -0
- data/vendor/spidermonkey/fdlibm/k_standard.c +785 -0
- data/vendor/spidermonkey/fdlibm/k_tan.c +170 -0
- data/vendor/spidermonkey/fdlibm/s_asinh.c +101 -0
- data/vendor/spidermonkey/fdlibm/s_atan.c +175 -0
- data/vendor/spidermonkey/fdlibm/s_cbrt.c +133 -0
- data/vendor/spidermonkey/fdlibm/s_ceil.c +120 -0
- data/vendor/spidermonkey/fdlibm/s_copysign.c +72 -0
- data/vendor/spidermonkey/fdlibm/s_cos.c +118 -0
- data/vendor/spidermonkey/fdlibm/s_erf.c +356 -0
- data/vendor/spidermonkey/fdlibm/s_expm1.c +267 -0
- data/vendor/spidermonkey/fdlibm/s_fabs.c +70 -0
- data/vendor/spidermonkey/fdlibm/s_finite.c +71 -0
- data/vendor/spidermonkey/fdlibm/s_floor.c +121 -0
- data/vendor/spidermonkey/fdlibm/s_frexp.c +99 -0
- data/vendor/spidermonkey/fdlibm/s_ilogb.c +85 -0
- data/vendor/spidermonkey/fdlibm/s_isnan.c +74 -0
- data/vendor/spidermonkey/fdlibm/s_ldexp.c +66 -0
- data/vendor/spidermonkey/fdlibm/s_lib_version.c +73 -0
- data/vendor/spidermonkey/fdlibm/s_log1p.c +211 -0
- data/vendor/spidermonkey/fdlibm/s_logb.c +79 -0
- data/vendor/spidermonkey/fdlibm/s_matherr.c +64 -0
- data/vendor/spidermonkey/fdlibm/s_modf.c +132 -0
- data/vendor/spidermonkey/fdlibm/s_nextafter.c +124 -0
- data/vendor/spidermonkey/fdlibm/s_rint.c +131 -0
- data/vendor/spidermonkey/fdlibm/s_scalbn.c +107 -0
- data/vendor/spidermonkey/fdlibm/s_signgam.c +40 -0
- data/vendor/spidermonkey/fdlibm/s_significand.c +68 -0
- data/vendor/spidermonkey/fdlibm/s_sin.c +118 -0
- data/vendor/spidermonkey/fdlibm/s_tan.c +112 -0
- data/vendor/spidermonkey/fdlibm/s_tanh.c +122 -0
- data/vendor/spidermonkey/fdlibm/w_acos.c +78 -0
- data/vendor/spidermonkey/fdlibm/w_acosh.c +78 -0
- data/vendor/spidermonkey/fdlibm/w_asin.c +80 -0
- data/vendor/spidermonkey/fdlibm/w_atan2.c +79 -0
- data/vendor/spidermonkey/fdlibm/w_atanh.c +81 -0
- data/vendor/spidermonkey/fdlibm/w_cosh.c +77 -0
- data/vendor/spidermonkey/fdlibm/w_exp.c +88 -0
- data/vendor/spidermonkey/fdlibm/w_fmod.c +78 -0
- data/vendor/spidermonkey/fdlibm/w_gamma.c +85 -0
- data/vendor/spidermonkey/fdlibm/w_gamma_r.c +81 -0
- data/vendor/spidermonkey/fdlibm/w_hypot.c +78 -0
- data/vendor/spidermonkey/fdlibm/w_j0.c +105 -0
- data/vendor/spidermonkey/fdlibm/w_j1.c +106 -0
- data/vendor/spidermonkey/fdlibm/w_jn.c +128 -0
- data/vendor/spidermonkey/fdlibm/w_lgamma.c +85 -0
- data/vendor/spidermonkey/fdlibm/w_lgamma_r.c +81 -0
- data/vendor/spidermonkey/fdlibm/w_log.c +78 -0
- data/vendor/spidermonkey/fdlibm/w_log10.c +81 -0
- data/vendor/spidermonkey/fdlibm/w_pow.c +99 -0
- data/vendor/spidermonkey/fdlibm/w_remainder.c +77 -0
- data/vendor/spidermonkey/fdlibm/w_scalb.c +95 -0
- data/vendor/spidermonkey/fdlibm/w_sinh.c +77 -0
- data/vendor/spidermonkey/fdlibm/w_sqrt.c +77 -0
- data/vendor/spidermonkey/javascript-trace.d +73 -0
- data/vendor/spidermonkey/js.c +3951 -0
- data/vendor/spidermonkey/js.mak +4438 -0
- data/vendor/spidermonkey/js.mdp +0 -0
- data/vendor/spidermonkey/js.msg +307 -0
- data/vendor/spidermonkey/js.pkg +2 -0
- data/vendor/spidermonkey/js3240.rc +79 -0
- data/vendor/spidermonkey/jsOS240.def +654 -0
- data/vendor/spidermonkey/jsapi.c +5836 -0
- data/vendor/spidermonkey/jsapi.h +2624 -0
- data/vendor/spidermonkey/jsarena.c +450 -0
- data/vendor/spidermonkey/jsarena.h +318 -0
- data/vendor/spidermonkey/jsarray.c +2988 -0
- data/vendor/spidermonkey/jsarray.h +124 -0
- data/vendor/spidermonkey/jsatom.c +1045 -0
- data/vendor/spidermonkey/jsatom.h +442 -0
- data/vendor/spidermonkey/jsbit.h +253 -0
- data/vendor/spidermonkey/jsbool.c +176 -0
- data/vendor/spidermonkey/jsbool.h +73 -0
- data/vendor/spidermonkey/jsclist.h +139 -0
- data/vendor/spidermonkey/jscntxt.c +1348 -0
- data/vendor/spidermonkey/jscntxt.h +1120 -0
- data/vendor/spidermonkey/jscompat.h +57 -0
- data/vendor/spidermonkey/jsconfig.h +248 -0
- data/vendor/spidermonkey/jsconfig.mk +181 -0
- data/vendor/spidermonkey/jscpucfg.c +383 -0
- data/vendor/spidermonkey/jscpucfg.h +212 -0
- data/vendor/spidermonkey/jsdate.c +2398 -0
- data/vendor/spidermonkey/jsdate.h +124 -0
- data/vendor/spidermonkey/jsdbgapi.c +1799 -0
- data/vendor/spidermonkey/jsdbgapi.h +464 -0
- data/vendor/spidermonkey/jsdhash.c +868 -0
- data/vendor/spidermonkey/jsdhash.h +592 -0
- data/vendor/spidermonkey/jsdtoa.c +3167 -0
- data/vendor/spidermonkey/jsdtoa.h +130 -0
- data/vendor/spidermonkey/jsdtracef.c +317 -0
- data/vendor/spidermonkey/jsdtracef.h +77 -0
- data/vendor/spidermonkey/jsemit.c +6909 -0
- data/vendor/spidermonkey/jsemit.h +741 -0
- data/vendor/spidermonkey/jsexn.c +1371 -0
- data/vendor/spidermonkey/jsexn.h +96 -0
- data/vendor/spidermonkey/jsfile.c +2736 -0
- data/vendor/spidermonkey/jsfile.h +56 -0
- data/vendor/spidermonkey/jsfile.msg +90 -0
- data/vendor/spidermonkey/jsfun.c +2634 -0
- data/vendor/spidermonkey/jsfun.h +254 -0
- data/vendor/spidermonkey/jsgc.c +3554 -0
- data/vendor/spidermonkey/jsgc.h +403 -0
- data/vendor/spidermonkey/jshash.c +476 -0
- data/vendor/spidermonkey/jshash.h +151 -0
- data/vendor/spidermonkey/jsify.pl +485 -0
- data/vendor/spidermonkey/jsinterp.c +6981 -0
- data/vendor/spidermonkey/jsinterp.h +521 -0
- data/vendor/spidermonkey/jsinvoke.c +43 -0
- data/vendor/spidermonkey/jsiter.c +1067 -0
- data/vendor/spidermonkey/jsiter.h +122 -0
- data/vendor/spidermonkey/jskeyword.tbl +124 -0
- data/vendor/spidermonkey/jskwgen.c +460 -0
- data/vendor/spidermonkey/jslibmath.h +266 -0
- data/vendor/spidermonkey/jslock.c +1309 -0
- data/vendor/spidermonkey/jslock.h +313 -0
- data/vendor/spidermonkey/jslocko.asm +60 -0
- data/vendor/spidermonkey/jslog2.c +94 -0
- data/vendor/spidermonkey/jslong.c +264 -0
- data/vendor/spidermonkey/jslong.h +412 -0
- data/vendor/spidermonkey/jsmath.c +568 -0
- data/vendor/spidermonkey/jsmath.h +57 -0
- data/vendor/spidermonkey/jsnum.c +1228 -0
- data/vendor/spidermonkey/jsnum.h +283 -0
- data/vendor/spidermonkey/jsobj.c +5266 -0
- data/vendor/spidermonkey/jsobj.h +709 -0
- data/vendor/spidermonkey/jsopcode.c +5245 -0
- data/vendor/spidermonkey/jsopcode.h +394 -0
- data/vendor/spidermonkey/jsopcode.tbl +523 -0
- data/vendor/spidermonkey/jsotypes.h +202 -0
- data/vendor/spidermonkey/jsparse.c +6680 -0
- data/vendor/spidermonkey/jsparse.h +511 -0
- data/vendor/spidermonkey/jsprf.c +1262 -0
- data/vendor/spidermonkey/jsprf.h +150 -0
- data/vendor/spidermonkey/jsproto.tbl +128 -0
- data/vendor/spidermonkey/jsprvtd.h +267 -0
- data/vendor/spidermonkey/jspubtd.h +744 -0
- data/vendor/spidermonkey/jsregexp.c +4352 -0
- data/vendor/spidermonkey/jsregexp.h +183 -0
- data/vendor/spidermonkey/jsreops.tbl +145 -0
- data/vendor/spidermonkey/jsscan.c +2003 -0
- data/vendor/spidermonkey/jsscan.h +387 -0
- data/vendor/spidermonkey/jsscope.c +1948 -0
- data/vendor/spidermonkey/jsscope.h +418 -0
- data/vendor/spidermonkey/jsscript.c +1832 -0
- data/vendor/spidermonkey/jsscript.h +287 -0
- data/vendor/spidermonkey/jsshell.msg +50 -0
- data/vendor/spidermonkey/jsstddef.h +83 -0
- data/vendor/spidermonkey/jsstr.c +5004 -0
- data/vendor/spidermonkey/jsstr.h +641 -0
- data/vendor/spidermonkey/jstypes.h +475 -0
- data/vendor/spidermonkey/jsutil.c +345 -0
- data/vendor/spidermonkey/jsutil.h +157 -0
- data/vendor/spidermonkey/jsxdrapi.c +800 -0
- data/vendor/spidermonkey/jsxdrapi.h +218 -0
- data/vendor/spidermonkey/jsxml.c +8471 -0
- data/vendor/spidermonkey/jsxml.h +349 -0
- data/vendor/spidermonkey/lock_SunOS.s +119 -0
- data/vendor/spidermonkey/perfect.js +39 -0
- data/vendor/spidermonkey/plify_jsdhash.sed +36 -0
- data/vendor/spidermonkey/prmjtime.c +846 -0
- data/vendor/spidermonkey/prmjtime.h +103 -0
- data/vendor/spidermonkey/resource.h +15 -0
- data/vendor/spidermonkey/rules.mk +197 -0
- data/vendor/spidermonkey/win32.order +384 -0
- metadata +4 -3
@@ -0,0 +1,124 @@
|
|
1
|
+
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2
|
+
*
|
3
|
+
* ***** BEGIN LICENSE BLOCK *****
|
4
|
+
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
5
|
+
*
|
6
|
+
* The contents of this file are subject to the Mozilla Public License Version
|
7
|
+
* 1.1 (the "License"); you may not use this file except in compliance with
|
8
|
+
* the License. You may obtain a copy of the License at
|
9
|
+
* http://www.mozilla.org/MPL/
|
10
|
+
*
|
11
|
+
* Software distributed under the License is distributed on an "AS IS" basis,
|
12
|
+
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
13
|
+
* for the specific language governing rights and limitations under the
|
14
|
+
* License.
|
15
|
+
*
|
16
|
+
* The Original Code is Mozilla Communicator client code, released
|
17
|
+
* March 31, 1998.
|
18
|
+
*
|
19
|
+
* The Initial Developer of the Original Code is
|
20
|
+
* Netscape Communications Corporation.
|
21
|
+
* Portions created by the Initial Developer are Copyright (C) 1998
|
22
|
+
* the Initial Developer. All Rights Reserved.
|
23
|
+
*
|
24
|
+
* Contributor(s):
|
25
|
+
*
|
26
|
+
* Alternatively, the contents of this file may be used under the terms of
|
27
|
+
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
28
|
+
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
29
|
+
* in which case the provisions of the GPL or the LGPL are applicable instead
|
30
|
+
* of those above. If you wish to allow use of your version of this file only
|
31
|
+
* under the terms of either the GPL or the LGPL, and not to allow others to
|
32
|
+
* use your version of this file under the terms of the MPL, indicate your
|
33
|
+
* decision by deleting the provisions above and replace them with the notice
|
34
|
+
* and other provisions required by the GPL or the LGPL. If you do not delete
|
35
|
+
* the provisions above, a recipient may use your version of this file under
|
36
|
+
* the terms of any one of the MPL, the GPL or the LGPL.
|
37
|
+
*
|
38
|
+
* ***** END LICENSE BLOCK ***** */
|
39
|
+
|
40
|
+
#ifndef jsarray_h___
|
41
|
+
#define jsarray_h___
|
42
|
+
/*
|
43
|
+
* JS Array interface.
|
44
|
+
*/
|
45
|
+
#include "jsprvtd.h"
|
46
|
+
#include "jspubtd.h"
|
47
|
+
|
48
|
+
JS_BEGIN_EXTERN_C
|
49
|
+
|
50
|
+
/* Generous sanity-bound on length (in elements) of array initialiser. */
|
51
|
+
#define ARRAY_INIT_LIMIT JS_BIT(24)
|
52
|
+
|
53
|
+
extern JSBool
|
54
|
+
js_IdIsIndex(jsval id, jsuint *indexp);
|
55
|
+
|
56
|
+
extern JSClass js_ArrayClass, js_SlowArrayClass;
|
57
|
+
|
58
|
+
#define OBJ_IS_DENSE_ARRAY(cx,obj) (OBJ_GET_CLASS(cx, obj) == &js_ArrayClass)
|
59
|
+
|
60
|
+
#define OBJ_IS_ARRAY(cx,obj) (OBJ_IS_DENSE_ARRAY(cx, obj) || \
|
61
|
+
OBJ_GET_CLASS(cx, obj) == &js_SlowArrayClass)
|
62
|
+
|
63
|
+
extern JSObject *
|
64
|
+
js_InitArrayClass(JSContext *cx, JSObject *obj);
|
65
|
+
|
66
|
+
extern JSObject *
|
67
|
+
js_NewArrayObject(JSContext *cx, jsuint length, jsval *vector);
|
68
|
+
|
69
|
+
/* Create an array object that starts out already made slow/sparse. */
|
70
|
+
extern JSObject *
|
71
|
+
js_NewSlowArrayObject(JSContext *cx);
|
72
|
+
|
73
|
+
#define JSSLOT_ARRAY_LENGTH JSSLOT_PRIVATE
|
74
|
+
#define JSSLOT_ARRAY_COUNT (JSSLOT_ARRAY_LENGTH + 1)
|
75
|
+
#define JSSLOT_ARRAY_LOOKUP_HOLDER (JSSLOT_ARRAY_COUNT + 1)
|
76
|
+
|
77
|
+
#define ARRAY_DENSE_LENGTH(obj) \
|
78
|
+
(JS_ASSERT(OBJ_IS_DENSE_ARRAY(cx, obj)), \
|
79
|
+
(obj)->dslots ? (uint32)(obj)->dslots[-1] : 0)
|
80
|
+
|
81
|
+
extern JSBool
|
82
|
+
js_GetLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);
|
83
|
+
|
84
|
+
extern JSBool
|
85
|
+
js_SetLengthProperty(JSContext *cx, JSObject *obj, jsuint length);
|
86
|
+
|
87
|
+
extern JSBool
|
88
|
+
js_HasLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);
|
89
|
+
|
90
|
+
/*
|
91
|
+
* Test whether an object is "array-like". Currently this means whether obj
|
92
|
+
* is an Array or an arguments object. We would like an API, and probably a
|
93
|
+
* way in the language, to bless other objects as array-like: having indexed
|
94
|
+
* properties, and a 'length' property of uint32 value equal to one more than
|
95
|
+
* the greatest index.
|
96
|
+
*/
|
97
|
+
extern JSBool
|
98
|
+
js_IsArrayLike(JSContext *cx, JSObject *obj, JSBool *answerp, jsuint *lengthp);
|
99
|
+
|
100
|
+
/*
|
101
|
+
* JS-specific merge sort function.
|
102
|
+
*/
|
103
|
+
typedef JSBool (*JSComparator)(void *arg, const void *a, const void *b,
|
104
|
+
int *result);
|
105
|
+
/*
|
106
|
+
* NB: vec is the array to be sorted, tmp is temporary space at least as big
|
107
|
+
* as vec. Both should be GC-rooted if appropriate.
|
108
|
+
*
|
109
|
+
* The sorted result is in vec. vec may be in an inconsistent state if the
|
110
|
+
* comparator function cmp returns an error inside a comparison, so remember
|
111
|
+
* to check the return value of this function.
|
112
|
+
*/
|
113
|
+
extern JSBool
|
114
|
+
js_MergeSort(void *vec, size_t nel, size_t elsize, JSComparator cmp,
|
115
|
+
void *arg, void *tmp);
|
116
|
+
|
117
|
+
#ifdef DEBUG_ARRAYS
|
118
|
+
extern JSBool
|
119
|
+
js_ArrayInfo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
|
120
|
+
#endif
|
121
|
+
|
122
|
+
JS_END_EXTERN_C
|
123
|
+
|
124
|
+
#endif /* jsarray_h___ */
|
@@ -0,0 +1,1045 @@
|
|
1
|
+
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2
|
+
*
|
3
|
+
* ***** BEGIN LICENSE BLOCK *****
|
4
|
+
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
5
|
+
*
|
6
|
+
* The contents of this file are subject to the Mozilla Public License Version
|
7
|
+
* 1.1 (the "License"); you may not use this file except in compliance with
|
8
|
+
* the License. You may obtain a copy of the License at
|
9
|
+
* http://www.mozilla.org/MPL/
|
10
|
+
*
|
11
|
+
* Software distributed under the License is distributed on an "AS IS" basis,
|
12
|
+
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
13
|
+
* for the specific language governing rights and limitations under the
|
14
|
+
* License.
|
15
|
+
*
|
16
|
+
* The Original Code is Mozilla Communicator client code, released
|
17
|
+
* March 31, 1998.
|
18
|
+
*
|
19
|
+
* The Initial Developer of the Original Code is
|
20
|
+
* Netscape Communications Corporation.
|
21
|
+
* Portions created by the Initial Developer are Copyright (C) 1998
|
22
|
+
* the Initial Developer. All Rights Reserved.
|
23
|
+
*
|
24
|
+
* Contributor(s):
|
25
|
+
*
|
26
|
+
* Alternatively, the contents of this file may be used under the terms of
|
27
|
+
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
28
|
+
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
29
|
+
* in which case the provisions of the GPL or the LGPL are applicable instead
|
30
|
+
* of those above. If you wish to allow use of your version of this file only
|
31
|
+
* under the terms of either the GPL or the LGPL, and not to allow others to
|
32
|
+
* use your version of this file under the terms of the MPL, indicate your
|
33
|
+
* decision by deleting the provisions above and replace them with the notice
|
34
|
+
* and other provisions required by the GPL or the LGPL. If you do not delete
|
35
|
+
* the provisions above, a recipient may use your version of this file under
|
36
|
+
* the terms of any one of the MPL, the GPL or the LGPL.
|
37
|
+
*
|
38
|
+
* ***** END LICENSE BLOCK ***** */
|
39
|
+
|
40
|
+
/*
|
41
|
+
* JS atom table.
|
42
|
+
*/
|
43
|
+
#include "jsstddef.h"
|
44
|
+
#include <stdlib.h>
|
45
|
+
#include <string.h>
|
46
|
+
#include "jstypes.h"
|
47
|
+
#include "jsutil.h" /* Added by JSIFY */
|
48
|
+
#include "jshash.h" /* Added by JSIFY */
|
49
|
+
#include "jsprf.h"
|
50
|
+
#include "jsapi.h"
|
51
|
+
#include "jsatom.h"
|
52
|
+
#include "jscntxt.h"
|
53
|
+
#include "jsconfig.h"
|
54
|
+
#include "jsgc.h"
|
55
|
+
#include "jslock.h"
|
56
|
+
#include "jsnum.h"
|
57
|
+
#include "jsscan.h"
|
58
|
+
#include "jsstr.h"
|
59
|
+
|
60
|
+
const char *
|
61
|
+
js_AtomToPrintableString(JSContext *cx, JSAtom *atom)
|
62
|
+
{
|
63
|
+
return js_ValueToPrintableString(cx, ATOM_KEY(atom));
|
64
|
+
}
|
65
|
+
|
66
|
+
#define JS_PROTO(name,code,init) const char js_##name##_str[] = #name;
|
67
|
+
#include "jsproto.tbl"
|
68
|
+
#undef JS_PROTO
|
69
|
+
|
70
|
+
/*
|
71
|
+
* Names for common atoms defined in JSAtomState starting from
|
72
|
+
* JSAtomState.emptyAtom until JSAtomState.lazy.
|
73
|
+
*
|
74
|
+
* The elements of the array after the first empty string define strings
|
75
|
+
* corresponding to JSType enumerators from jspubtd.h and to two boolean
|
76
|
+
* literals, false and true. The following assert insists that JSType defines
|
77
|
+
* exactly 8 types.
|
78
|
+
*/
|
79
|
+
JS_STATIC_ASSERT(JSTYPE_LIMIT == 8);
|
80
|
+
const char *const js_common_atom_names[] = {
|
81
|
+
"", /* emptyAtom */
|
82
|
+
js_undefined_str, /* typeAtoms[JSTYPE_VOID] */
|
83
|
+
js_object_str, /* typeAtoms[JSTYPE_OBJECT] */
|
84
|
+
js_function_str, /* typeAtoms[JSTYPE_FUNCTION] */
|
85
|
+
"string", /* typeAtoms[JSTYPE_STRING] */
|
86
|
+
"number", /* typeAtoms[JSTYPE_NUMBER] */
|
87
|
+
"boolean", /* typeAtoms[JSTYPE_BOOLEAN] */
|
88
|
+
js_null_str, /* typeAtoms[JSTYPE_NULL] */
|
89
|
+
"xml", /* typeAtoms[JSTYPE_XML] */
|
90
|
+
js_false_str, /* booleanAtoms[0] */
|
91
|
+
js_true_str, /* booleanAtoms[1] */
|
92
|
+
js_null_str, /* nullAtom */
|
93
|
+
|
94
|
+
#define JS_PROTO(name,code,init) js_##name##_str,
|
95
|
+
#include "jsproto.tbl"
|
96
|
+
#undef JS_PROTO
|
97
|
+
|
98
|
+
js_anonymous_str, /* anonymousAtom */
|
99
|
+
js_arguments_str, /* argumentsAtom */
|
100
|
+
js_arity_str, /* arityAtom */
|
101
|
+
js_callee_str, /* calleeAtom */
|
102
|
+
js_caller_str, /* callerAtom */
|
103
|
+
js_class_prototype_str, /* classPrototypeAtom */
|
104
|
+
js_constructor_str, /* constructorAtom */
|
105
|
+
js_count_str, /* countAtom */
|
106
|
+
js_each_str, /* eachAtom */
|
107
|
+
js_eval_str, /* evalAtom */
|
108
|
+
js_fileName_str, /* fileNameAtom */
|
109
|
+
js_get_str, /* getAtom */
|
110
|
+
js_getter_str, /* getterAtom */
|
111
|
+
js_index_str, /* indexAtom */
|
112
|
+
js_input_str, /* inputAtom */
|
113
|
+
js_iterator_str, /* iteratorAtom */
|
114
|
+
js_length_str, /* lengthAtom */
|
115
|
+
js_lineNumber_str, /* lineNumberAtom */
|
116
|
+
js_message_str, /* messageAtom */
|
117
|
+
js_name_str, /* nameAtom */
|
118
|
+
js_next_str, /* nextAtom */
|
119
|
+
js_noSuchMethod_str, /* noSuchMethodAtom */
|
120
|
+
js_parent_str, /* parentAtom */
|
121
|
+
js_proto_str, /* protoAtom */
|
122
|
+
js_set_str, /* setAtom */
|
123
|
+
js_setter_str, /* setterAtom */
|
124
|
+
js_stack_str, /* stackAtom */
|
125
|
+
js_toLocaleString_str, /* toLocaleStringAtom */
|
126
|
+
js_toSource_str, /* toSourceAtom */
|
127
|
+
js_toString_str, /* toStringAtom */
|
128
|
+
js_valueOf_str, /* valueOfAtom */
|
129
|
+
"(void 0)", /* void0Atom */
|
130
|
+
|
131
|
+
#if JS_HAS_XML_SUPPORT
|
132
|
+
js_etago_str, /* etagoAtom */
|
133
|
+
js_namespace_str, /* namespaceAtom */
|
134
|
+
js_ptagc_str, /* ptagcAtom */
|
135
|
+
js_qualifier_str, /* qualifierAtom */
|
136
|
+
js_space_str, /* spaceAtom */
|
137
|
+
js_stago_str, /* stagoAtom */
|
138
|
+
js_star_str, /* starAtom */
|
139
|
+
js_starQualifier_str, /* starQualifierAtom */
|
140
|
+
js_tagc_str, /* tagcAtom */
|
141
|
+
js_xml_str, /* xmlAtom */
|
142
|
+
#endif
|
143
|
+
|
144
|
+
#ifdef NARCISSUS
|
145
|
+
js_call_str, /* callAtom */
|
146
|
+
js_construct_str, /* constructAtom */
|
147
|
+
js_hasInstance_str, /* hasInstanceAtom */
|
148
|
+
js_ExecutionContext_str, /* ExecutionContextAtom */
|
149
|
+
js_current_str, /* currentAtom */
|
150
|
+
#endif
|
151
|
+
};
|
152
|
+
JS_STATIC_ASSERT(JS_ARRAY_LENGTH(js_common_atom_names) * sizeof(JSAtom *) ==
|
153
|
+
LAZY_ATOM_OFFSET_START - ATOM_OFFSET_START);
|
154
|
+
|
155
|
+
const char js_anonymous_str[] = "anonymous";
|
156
|
+
const char js_arguments_str[] = "arguments";
|
157
|
+
const char js_arity_str[] = "arity";
|
158
|
+
const char js_callee_str[] = "callee";
|
159
|
+
const char js_caller_str[] = "caller";
|
160
|
+
const char js_class_prototype_str[] = "prototype";
|
161
|
+
const char js_constructor_str[] = "constructor";
|
162
|
+
const char js_count_str[] = "__count__";
|
163
|
+
const char js_each_str[] = "each";
|
164
|
+
const char js_eval_str[] = "eval";
|
165
|
+
const char js_fileName_str[] = "fileName";
|
166
|
+
const char js_get_str[] = "get";
|
167
|
+
const char js_getter_str[] = "getter";
|
168
|
+
const char js_index_str[] = "index";
|
169
|
+
const char js_input_str[] = "input";
|
170
|
+
const char js_iterator_str[] = "__iterator__";
|
171
|
+
const char js_length_str[] = "length";
|
172
|
+
const char js_lineNumber_str[] = "lineNumber";
|
173
|
+
const char js_message_str[] = "message";
|
174
|
+
const char js_name_str[] = "name";
|
175
|
+
const char js_next_str[] = "next";
|
176
|
+
const char js_noSuchMethod_str[] = "__noSuchMethod__";
|
177
|
+
const char js_object_str[] = "object";
|
178
|
+
const char js_parent_str[] = "__parent__";
|
179
|
+
const char js_proto_str[] = "__proto__";
|
180
|
+
const char js_setter_str[] = "setter";
|
181
|
+
const char js_set_str[] = "set";
|
182
|
+
const char js_stack_str[] = "stack";
|
183
|
+
const char js_toSource_str[] = "toSource";
|
184
|
+
const char js_toString_str[] = "toString";
|
185
|
+
const char js_toLocaleString_str[] = "toLocaleString";
|
186
|
+
const char js_undefined_str[] = "undefined";
|
187
|
+
const char js_valueOf_str[] = "valueOf";
|
188
|
+
|
189
|
+
#if JS_HAS_XML_SUPPORT
|
190
|
+
const char js_etago_str[] = "</";
|
191
|
+
const char js_namespace_str[] = "namespace";
|
192
|
+
const char js_ptagc_str[] = "/>";
|
193
|
+
const char js_qualifier_str[] = "::";
|
194
|
+
const char js_space_str[] = " ";
|
195
|
+
const char js_stago_str[] = "<";
|
196
|
+
const char js_star_str[] = "*";
|
197
|
+
const char js_starQualifier_str[] = "*::";
|
198
|
+
const char js_tagc_str[] = ">";
|
199
|
+
const char js_xml_str[] = "xml";
|
200
|
+
#endif
|
201
|
+
|
202
|
+
#if JS_HAS_GENERATORS
|
203
|
+
const char js_close_str[] = "close";
|
204
|
+
const char js_send_str[] = "send";
|
205
|
+
#endif
|
206
|
+
|
207
|
+
#ifdef NARCISSUS
|
208
|
+
const char js_call_str[] = "__call__";
|
209
|
+
const char js_construct_str[] = "__construct__";
|
210
|
+
const char js_hasInstance_str[] = "__hasInstance__";
|
211
|
+
const char js_ExecutionContext_str[] = "ExecutionContext";
|
212
|
+
const char js_current_str[] = "current";
|
213
|
+
#endif
|
214
|
+
|
215
|
+
/*
|
216
|
+
* JSAtomState.doubleAtoms and JSAtomState.stringAtoms hashtable entry. To
|
217
|
+
* support pinned and interned string atoms, we use the lowest bits of the
|
218
|
+
* keyAndFlags field to store ATOM_PINNED and ATOM_INTERNED flags.
|
219
|
+
*/
|
220
|
+
typedef struct JSAtomHashEntry {
|
221
|
+
JSDHashEntryHdr hdr;
|
222
|
+
jsuword keyAndFlags;
|
223
|
+
} JSAtomHashEntry;
|
224
|
+
|
225
|
+
#define ATOM_ENTRY_FLAG_MASK (ATOM_PINNED | ATOM_INTERNED)
|
226
|
+
|
227
|
+
JS_STATIC_ASSERT(ATOM_ENTRY_FLAG_MASK < JSVAL_ALIGN);
|
228
|
+
|
229
|
+
/*
|
230
|
+
* Helper macros to access and modify JSAtomHashEntry.
|
231
|
+
*/
|
232
|
+
#define TO_ATOM_ENTRY(hdr) ((JSAtomHashEntry *) hdr)
|
233
|
+
#define ATOM_ENTRY_KEY(entry) \
|
234
|
+
((void *)((entry)->keyAndFlags & ~ATOM_ENTRY_FLAG_MASK))
|
235
|
+
#define ATOM_ENTRY_FLAGS(entry) \
|
236
|
+
((uintN)((entry)->keyAndFlags & ATOM_ENTRY_FLAG_MASK))
|
237
|
+
#define INIT_ATOM_ENTRY(entry, key) \
|
238
|
+
((void)((entry)->keyAndFlags = (jsuword)(key)))
|
239
|
+
#define ADD_ATOM_ENTRY_FLAGS(entry, flags) \
|
240
|
+
((void)((entry)->keyAndFlags |= (jsuword)(flags)))
|
241
|
+
#define CLEAR_ATOM_ENTRY_FLAGS(entry, flags) \
|
242
|
+
((void)((entry)->keyAndFlags &= ~(jsuword)(flags)))
|
243
|
+
|
244
|
+
JS_STATIC_DLL_CALLBACK(JSDHashNumber)
|
245
|
+
HashDouble(JSDHashTable *table, const void *key);
|
246
|
+
|
247
|
+
JS_STATIC_DLL_CALLBACK(JSBool)
|
248
|
+
MatchDouble(JSDHashTable *table, const JSDHashEntryHdr *hdr, const void *key);
|
249
|
+
|
250
|
+
JS_STATIC_DLL_CALLBACK(JSDHashNumber)
|
251
|
+
HashString(JSDHashTable *table, const void *key);
|
252
|
+
|
253
|
+
JS_STATIC_DLL_CALLBACK(JSBool)
|
254
|
+
MatchString(JSDHashTable *table, const JSDHashEntryHdr *hdr, const void *key);
|
255
|
+
|
256
|
+
static const JSDHashTableOps DoubleHashOps = {
|
257
|
+
JS_DHashAllocTable,
|
258
|
+
JS_DHashFreeTable,
|
259
|
+
HashDouble,
|
260
|
+
MatchDouble,
|
261
|
+
JS_DHashMoveEntryStub,
|
262
|
+
JS_DHashClearEntryStub,
|
263
|
+
JS_DHashFinalizeStub,
|
264
|
+
NULL
|
265
|
+
};
|
266
|
+
|
267
|
+
static const JSDHashTableOps StringHashOps = {
|
268
|
+
JS_DHashAllocTable,
|
269
|
+
JS_DHashFreeTable,
|
270
|
+
HashString,
|
271
|
+
MatchString,
|
272
|
+
JS_DHashMoveEntryStub,
|
273
|
+
JS_DHashClearEntryStub,
|
274
|
+
JS_DHashFinalizeStub,
|
275
|
+
NULL
|
276
|
+
};
|
277
|
+
|
278
|
+
#define IS_DOUBLE_TABLE(table) ((table)->ops == &DoubleHashOps)
|
279
|
+
#define IS_STRING_TABLE(table) ((table)->ops == &StringHashOps)
|
280
|
+
|
281
|
+
#define IS_INITIALIZED_STATE(state) IS_DOUBLE_TABLE(&(state)->doubleAtoms)
|
282
|
+
|
283
|
+
JS_STATIC_DLL_CALLBACK(JSDHashNumber)
|
284
|
+
HashDouble(JSDHashTable *table, const void *key)
|
285
|
+
{
|
286
|
+
jsdouble d;
|
287
|
+
|
288
|
+
JS_ASSERT(IS_DOUBLE_TABLE(table));
|
289
|
+
d = *(jsdouble *)key;
|
290
|
+
return JSDOUBLE_HI32(d) ^ JSDOUBLE_LO32(d);
|
291
|
+
}
|
292
|
+
|
293
|
+
JS_STATIC_DLL_CALLBACK(JSDHashNumber)
|
294
|
+
HashString(JSDHashTable *table, const void *key)
|
295
|
+
{
|
296
|
+
JS_ASSERT(IS_STRING_TABLE(table));
|
297
|
+
return js_HashString((JSString *)key);
|
298
|
+
}
|
299
|
+
|
300
|
+
JS_STATIC_DLL_CALLBACK(JSBool)
|
301
|
+
MatchDouble(JSDHashTable *table, const JSDHashEntryHdr *hdr, const void *key)
|
302
|
+
{
|
303
|
+
JSAtomHashEntry *entry = TO_ATOM_ENTRY(hdr);
|
304
|
+
jsdouble d1, d2;
|
305
|
+
|
306
|
+
JS_ASSERT(IS_DOUBLE_TABLE(table));
|
307
|
+
if (entry->keyAndFlags == 0) {
|
308
|
+
/* See comments in MatchString. */
|
309
|
+
return JS_FALSE;
|
310
|
+
}
|
311
|
+
|
312
|
+
d1 = *(jsdouble *)ATOM_ENTRY_KEY(entry);
|
313
|
+
d2 = *(jsdouble *)key;
|
314
|
+
if (JSDOUBLE_IS_NaN(d1))
|
315
|
+
return JSDOUBLE_IS_NaN(d2);
|
316
|
+
#if defined(XP_WIN)
|
317
|
+
/* XXX MSVC miscompiles such that (NaN == 0) */
|
318
|
+
if (JSDOUBLE_IS_NaN(d2))
|
319
|
+
return JS_FALSE;
|
320
|
+
#endif
|
321
|
+
return d1 == d2;
|
322
|
+
}
|
323
|
+
|
324
|
+
JS_STATIC_DLL_CALLBACK(JSBool)
|
325
|
+
MatchString(JSDHashTable *table, const JSDHashEntryHdr *hdr, const void *key)
|
326
|
+
{
|
327
|
+
JSAtomHashEntry *entry = TO_ATOM_ENTRY(hdr);
|
328
|
+
|
329
|
+
JS_ASSERT(IS_STRING_TABLE(table));
|
330
|
+
if (entry->keyAndFlags == 0) {
|
331
|
+
/*
|
332
|
+
* This happens when js_AtomizeString adds a new hash entry and
|
333
|
+
* releases the lock but before it takes the lock the second time to
|
334
|
+
* initialize keyAndFlags for the entry.
|
335
|
+
*
|
336
|
+
* We always return false for such entries so JS_DHashTableOperate
|
337
|
+
* never finds them. We clean them during GC's sweep phase.
|
338
|
+
*
|
339
|
+
* It means that with a contested lock or when GC is triggered outside
|
340
|
+
* the lock we may end up adding two entries, but this is a price for
|
341
|
+
* simpler code.
|
342
|
+
*/
|
343
|
+
return JS_FALSE;
|
344
|
+
}
|
345
|
+
return js_EqualStrings((JSString *)ATOM_ENTRY_KEY(entry), (JSString *)key);
|
346
|
+
}
|
347
|
+
|
348
|
+
/*
|
349
|
+
* For a browser build from 2007-08-09 after the browser starts up there are
|
350
|
+
* just 55 double atoms, but over 15000 string atoms. Not to penalize more
|
351
|
+
* economical embeddings allocating too much memory initially we initialize
|
352
|
+
* atomized strings with just 1K entries.
|
353
|
+
*/
|
354
|
+
#define JS_STRING_HASH_COUNT 1024
|
355
|
+
#define JS_DOUBLE_HASH_COUNT 64
|
356
|
+
|
357
|
+
JSBool
|
358
|
+
js_InitAtomState(JSRuntime *rt)
|
359
|
+
{
|
360
|
+
JSAtomState *state = &rt->atomState;
|
361
|
+
|
362
|
+
/*
|
363
|
+
* The caller must zero the state before calling this function.
|
364
|
+
*/
|
365
|
+
JS_ASSERT(!state->stringAtoms.ops);
|
366
|
+
JS_ASSERT(!state->doubleAtoms.ops);
|
367
|
+
|
368
|
+
if (!JS_DHashTableInit(&state->stringAtoms, &StringHashOps,
|
369
|
+
NULL, sizeof(JSAtomHashEntry),
|
370
|
+
JS_DHASH_DEFAULT_CAPACITY(JS_STRING_HASH_COUNT))) {
|
371
|
+
state->stringAtoms.ops = NULL;
|
372
|
+
return JS_FALSE;
|
373
|
+
}
|
374
|
+
JS_ASSERT(IS_STRING_TABLE(&state->stringAtoms));
|
375
|
+
|
376
|
+
if (!JS_DHashTableInit(&state->doubleAtoms, &DoubleHashOps,
|
377
|
+
NULL, sizeof(JSAtomHashEntry),
|
378
|
+
JS_DHASH_DEFAULT_CAPACITY(JS_DOUBLE_HASH_COUNT))) {
|
379
|
+
state->doubleAtoms.ops = NULL;
|
380
|
+
JS_DHashTableFinish(&state->stringAtoms);
|
381
|
+
state->stringAtoms.ops = NULL;
|
382
|
+
return JS_FALSE;
|
383
|
+
}
|
384
|
+
JS_ASSERT(IS_DOUBLE_TABLE(&state->doubleAtoms));
|
385
|
+
|
386
|
+
#ifdef JS_THREADSAFE
|
387
|
+
js_InitLock(&state->lock);
|
388
|
+
#endif
|
389
|
+
JS_ASSERT(IS_INITIALIZED_STATE(state));
|
390
|
+
return JS_TRUE;
|
391
|
+
}
|
392
|
+
|
393
|
+
JS_STATIC_DLL_CALLBACK(JSDHashOperator)
|
394
|
+
js_string_uninterner(JSDHashTable *table, JSDHashEntryHdr *hdr,
|
395
|
+
uint32 number, void *arg)
|
396
|
+
{
|
397
|
+
JSAtomHashEntry *entry = TO_ATOM_ENTRY(hdr);
|
398
|
+
JSRuntime *rt = (JSRuntime *)arg;
|
399
|
+
JSString *str;
|
400
|
+
|
401
|
+
/*
|
402
|
+
* Any string entry that remains at this point must be initialized, as the
|
403
|
+
* last GC should clean any uninitialized ones.
|
404
|
+
*/
|
405
|
+
JS_ASSERT(IS_STRING_TABLE(table));
|
406
|
+
JS_ASSERT(entry->keyAndFlags != 0);
|
407
|
+
str = (JSString *)ATOM_ENTRY_KEY(entry);
|
408
|
+
|
409
|
+
/* Pass null as context. */
|
410
|
+
js_FinalizeStringRT(rt, str, js_GetExternalStringGCType(str), NULL);
|
411
|
+
return JS_DHASH_NEXT;
|
412
|
+
}
|
413
|
+
|
414
|
+
void
|
415
|
+
js_FinishAtomState(JSRuntime *rt)
|
416
|
+
{
|
417
|
+
JSAtomState *state = &rt->atomState;
|
418
|
+
|
419
|
+
if (!IS_INITIALIZED_STATE(state)) {
|
420
|
+
/*
|
421
|
+
* We are called with uninitialized state when JS_NewRuntime fails and
|
422
|
+
* calls JS_DestroyRuntime on a partially initialized runtime.
|
423
|
+
*/
|
424
|
+
return;
|
425
|
+
}
|
426
|
+
|
427
|
+
JS_DHashTableEnumerate(&state->stringAtoms, js_string_uninterner, rt);
|
428
|
+
JS_DHashTableFinish(&state->stringAtoms);
|
429
|
+
JS_DHashTableFinish(&state->doubleAtoms);
|
430
|
+
|
431
|
+
#ifdef JS_THREADSAFE
|
432
|
+
js_FinishLock(&state->lock);
|
433
|
+
#endif
|
434
|
+
#ifdef DEBUG
|
435
|
+
memset(state, JS_FREE_PATTERN, sizeof *state);
|
436
|
+
#endif
|
437
|
+
}
|
438
|
+
|
439
|
+
JSBool
|
440
|
+
js_InitCommonAtoms(JSContext *cx)
|
441
|
+
{
|
442
|
+
JSAtomState *state = &cx->runtime->atomState;
|
443
|
+
uintN i;
|
444
|
+
JSAtom **atoms;
|
445
|
+
|
446
|
+
atoms = COMMON_ATOMS_START(state);
|
447
|
+
for (i = 0; i < JS_ARRAY_LENGTH(js_common_atom_names); i++, atoms++) {
|
448
|
+
*atoms = js_Atomize(cx, js_common_atom_names[i],
|
449
|
+
strlen(js_common_atom_names[i]), ATOM_PINNED);
|
450
|
+
if (!*atoms)
|
451
|
+
return JS_FALSE;
|
452
|
+
}
|
453
|
+
JS_ASSERT((uint8 *)atoms - (uint8 *)state == LAZY_ATOM_OFFSET_START);
|
454
|
+
memset(atoms, 0, ATOM_OFFSET_LIMIT - LAZY_ATOM_OFFSET_START);
|
455
|
+
|
456
|
+
return JS_TRUE;
|
457
|
+
}
|
458
|
+
|
459
|
+
JS_STATIC_DLL_CALLBACK(JSDHashOperator)
|
460
|
+
js_atom_unpinner(JSDHashTable *table, JSDHashEntryHdr *hdr,
|
461
|
+
uint32 number, void *arg)
|
462
|
+
{
|
463
|
+
JS_ASSERT(IS_STRING_TABLE(table));
|
464
|
+
CLEAR_ATOM_ENTRY_FLAGS(TO_ATOM_ENTRY(hdr), ATOM_PINNED);
|
465
|
+
return JS_DHASH_NEXT;
|
466
|
+
}
|
467
|
+
|
468
|
+
void
|
469
|
+
js_FinishCommonAtoms(JSContext *cx)
|
470
|
+
{
|
471
|
+
JSAtomState *state = &cx->runtime->atomState;
|
472
|
+
|
473
|
+
JS_DHashTableEnumerate(&state->stringAtoms, js_atom_unpinner, NULL);
|
474
|
+
#ifdef DEBUG
|
475
|
+
memset(COMMON_ATOMS_START(state), JS_FREE_PATTERN,
|
476
|
+
ATOM_OFFSET_LIMIT - ATOM_OFFSET_START);
|
477
|
+
#endif
|
478
|
+
}
|
479
|
+
|
480
|
+
JS_STATIC_DLL_CALLBACK(JSDHashOperator)
|
481
|
+
js_locked_atom_tracer(JSDHashTable *table, JSDHashEntryHdr *hdr,
|
482
|
+
uint32 number, void *arg)
|
483
|
+
{
|
484
|
+
JSAtomHashEntry *entry = TO_ATOM_ENTRY(hdr);
|
485
|
+
JSTracer *trc = (JSTracer *)arg;
|
486
|
+
|
487
|
+
if (entry->keyAndFlags == 0) {
|
488
|
+
/* Ignore uninitialized entries during tracing. */
|
489
|
+
return JS_DHASH_NEXT;
|
490
|
+
}
|
491
|
+
JS_SET_TRACING_INDEX(trc, "locked_atom", (size_t)number);
|
492
|
+
JS_CallTracer(trc, ATOM_ENTRY_KEY(entry),
|
493
|
+
IS_STRING_TABLE(table) ? JSTRACE_STRING : JSTRACE_DOUBLE);
|
494
|
+
return JS_DHASH_NEXT;
|
495
|
+
}
|
496
|
+
|
497
|
+
JS_STATIC_DLL_CALLBACK(JSDHashOperator)
|
498
|
+
js_pinned_atom_tracer(JSDHashTable *table, JSDHashEntryHdr *hdr,
|
499
|
+
uint32 number, void *arg)
|
500
|
+
{
|
501
|
+
JSAtomHashEntry *entry = TO_ATOM_ENTRY(hdr);
|
502
|
+
JSTracer *trc = (JSTracer *)arg;
|
503
|
+
uintN flags = ATOM_ENTRY_FLAGS(entry);
|
504
|
+
|
505
|
+
JS_ASSERT(IS_STRING_TABLE(table));
|
506
|
+
if (flags & (ATOM_PINNED | ATOM_INTERNED)) {
|
507
|
+
JS_SET_TRACING_INDEX(trc,
|
508
|
+
flags & ATOM_PINNED
|
509
|
+
? "pinned_atom"
|
510
|
+
: "interned_atom",
|
511
|
+
(size_t)number);
|
512
|
+
JS_CallTracer(trc, ATOM_ENTRY_KEY(entry), JSTRACE_STRING);
|
513
|
+
}
|
514
|
+
return JS_DHASH_NEXT;
|
515
|
+
}
|
516
|
+
|
517
|
+
void
|
518
|
+
js_TraceAtomState(JSTracer *trc, JSBool allAtoms)
|
519
|
+
{
|
520
|
+
JSAtomState *state;
|
521
|
+
|
522
|
+
state = &trc->context->runtime->atomState;
|
523
|
+
if (allAtoms) {
|
524
|
+
JS_DHashTableEnumerate(&state->doubleAtoms, js_locked_atom_tracer, trc);
|
525
|
+
JS_DHashTableEnumerate(&state->stringAtoms, js_locked_atom_tracer, trc);
|
526
|
+
} else {
|
527
|
+
JS_DHashTableEnumerate(&state->stringAtoms, js_pinned_atom_tracer, trc);
|
528
|
+
}
|
529
|
+
}
|
530
|
+
|
531
|
+
JS_STATIC_DLL_CALLBACK(JSDHashOperator)
|
532
|
+
js_atom_sweeper(JSDHashTable *table, JSDHashEntryHdr *hdr,
|
533
|
+
uint32 number, void *arg)
|
534
|
+
{
|
535
|
+
JSAtomHashEntry *entry = TO_ATOM_ENTRY(hdr);
|
536
|
+
JSContext *cx = (JSContext *)arg;
|
537
|
+
|
538
|
+
/* Remove uninitialized entries. */
|
539
|
+
if (entry->keyAndFlags == 0)
|
540
|
+
return JS_DHASH_REMOVE;
|
541
|
+
|
542
|
+
if (ATOM_ENTRY_FLAGS(entry) & (ATOM_PINNED | ATOM_INTERNED)) {
|
543
|
+
/* Pinned or interned key cannot be finalized. */
|
544
|
+
JS_ASSERT(!js_IsAboutToBeFinalized(cx, ATOM_ENTRY_KEY(entry)));
|
545
|
+
} else if (js_IsAboutToBeFinalized(cx, ATOM_ENTRY_KEY(entry))) {
|
546
|
+
/* Remove entries with things about to be GC'ed. */
|
547
|
+
return JS_DHASH_REMOVE;
|
548
|
+
}
|
549
|
+
return JS_DHASH_NEXT;
|
550
|
+
}
|
551
|
+
|
552
|
+
void
|
553
|
+
js_SweepAtomState(JSContext *cx)
|
554
|
+
{
|
555
|
+
JSAtomState *state = &cx->runtime->atomState;
|
556
|
+
|
557
|
+
JS_DHashTableEnumerate(&state->doubleAtoms, js_atom_sweeper, cx);
|
558
|
+
JS_DHashTableEnumerate(&state->stringAtoms, js_atom_sweeper, cx);
|
559
|
+
|
560
|
+
/*
|
561
|
+
* Optimize for simplicity and mutate table generation numbers even if the
|
562
|
+
* sweeper has not removed any entries.
|
563
|
+
*/
|
564
|
+
state->doubleAtoms.generation++;
|
565
|
+
state->stringAtoms.generation++;
|
566
|
+
}
|
567
|
+
|
568
|
+
JSAtom *
|
569
|
+
js_AtomizeDouble(JSContext *cx, jsdouble d)
|
570
|
+
{
|
571
|
+
JSAtomState *state;
|
572
|
+
JSDHashTable *table;
|
573
|
+
JSAtomHashEntry *entry;
|
574
|
+
uint32 gen;
|
575
|
+
jsdouble *key;
|
576
|
+
jsval v;
|
577
|
+
|
578
|
+
state = &cx->runtime->atomState;
|
579
|
+
table = &state->doubleAtoms;
|
580
|
+
|
581
|
+
JS_LOCK(&state->lock, cx);
|
582
|
+
entry = TO_ATOM_ENTRY(JS_DHashTableOperate(table, &d, JS_DHASH_ADD));
|
583
|
+
if (!entry)
|
584
|
+
goto failed_hash_add;
|
585
|
+
if (entry->keyAndFlags == 0) {
|
586
|
+
gen = ++table->generation;
|
587
|
+
JS_UNLOCK(&state->lock, cx);
|
588
|
+
|
589
|
+
key = js_NewWeaklyRootedDouble(cx, d);
|
590
|
+
if (!key)
|
591
|
+
return NULL;
|
592
|
+
|
593
|
+
JS_LOCK(&state->lock, cx);
|
594
|
+
if (table->generation == gen) {
|
595
|
+
JS_ASSERT(entry->keyAndFlags == 0);
|
596
|
+
} else {
|
597
|
+
entry = TO_ATOM_ENTRY(JS_DHashTableOperate(table, key,
|
598
|
+
JS_DHASH_ADD));
|
599
|
+
if (!entry)
|
600
|
+
goto failed_hash_add;
|
601
|
+
if (entry->keyAndFlags != 0)
|
602
|
+
goto finish;
|
603
|
+
++table->generation;
|
604
|
+
}
|
605
|
+
INIT_ATOM_ENTRY(entry, key);
|
606
|
+
}
|
607
|
+
|
608
|
+
finish:
|
609
|
+
v = DOUBLE_TO_JSVAL((jsdouble *)ATOM_ENTRY_KEY(entry));
|
610
|
+
cx->weakRoots.lastAtom = v;
|
611
|
+
JS_UNLOCK(&state->lock,cx);
|
612
|
+
|
613
|
+
return (JSAtom *)v;
|
614
|
+
|
615
|
+
failed_hash_add:
|
616
|
+
JS_UNLOCK(&state->lock,cx);
|
617
|
+
JS_ReportOutOfMemory(cx);
|
618
|
+
return NULL;
|
619
|
+
}
|
620
|
+
|
621
|
+
JSAtom *
|
622
|
+
js_AtomizeString(JSContext *cx, JSString *str, uintN flags)
|
623
|
+
{
|
624
|
+
jsval v;
|
625
|
+
JSAtomState *state;
|
626
|
+
JSDHashTable *table;
|
627
|
+
JSAtomHashEntry *entry;
|
628
|
+
JSString *key;
|
629
|
+
uint32 gen;
|
630
|
+
|
631
|
+
JS_ASSERT(!(flags & ~(ATOM_PINNED|ATOM_INTERNED|ATOM_TMPSTR|ATOM_NOCOPY)));
|
632
|
+
JS_ASSERT_IF(flags & ATOM_NOCOPY, flags & ATOM_TMPSTR);
|
633
|
+
|
634
|
+
state = &cx->runtime->atomState;
|
635
|
+
table = &state->stringAtoms;
|
636
|
+
|
637
|
+
JS_LOCK(&state->lock, cx);
|
638
|
+
entry = TO_ATOM_ENTRY(JS_DHashTableOperate(table, str, JS_DHASH_ADD));
|
639
|
+
if (!entry)
|
640
|
+
goto failed_hash_add;
|
641
|
+
if (entry->keyAndFlags != 0) {
|
642
|
+
key = (JSString *)ATOM_ENTRY_KEY(entry);
|
643
|
+
} else {
|
644
|
+
/*
|
645
|
+
* We created a new hashtable entry. Unless str is already allocated
|
646
|
+
* from the GC heap and flat, we have to release state->lock as
|
647
|
+
* string construction is a complex operation. For example, it can
|
648
|
+
* trigger GC which may rehash the table and make the entry invalid.
|
649
|
+
*/
|
650
|
+
++table->generation;
|
651
|
+
if (!(flags & ATOM_TMPSTR) && JSSTRING_IS_FLAT(str)) {
|
652
|
+
JSFLATSTR_CLEAR_MUTABLE(str);
|
653
|
+
key = str;
|
654
|
+
} else {
|
655
|
+
gen = table->generation;
|
656
|
+
JS_UNLOCK(&state->lock, cx);
|
657
|
+
|
658
|
+
if (flags & ATOM_TMPSTR) {
|
659
|
+
if (flags & ATOM_NOCOPY) {
|
660
|
+
key = js_NewString(cx, JSFLATSTR_CHARS(str),
|
661
|
+
JSFLATSTR_LENGTH(str));
|
662
|
+
if (!key)
|
663
|
+
return NULL;
|
664
|
+
|
665
|
+
/* Finish handing off chars to the GC'ed key string. */
|
666
|
+
str->u.chars = NULL;
|
667
|
+
} else {
|
668
|
+
key = js_NewStringCopyN(cx, JSFLATSTR_CHARS(str),
|
669
|
+
JSFLATSTR_LENGTH(str));
|
670
|
+
if (!key)
|
671
|
+
return NULL;
|
672
|
+
}
|
673
|
+
} else {
|
674
|
+
JS_ASSERT(JSSTRING_IS_DEPENDENT(str));
|
675
|
+
if (!js_UndependString(cx, str))
|
676
|
+
return NULL;
|
677
|
+
key = str;
|
678
|
+
}
|
679
|
+
|
680
|
+
JS_LOCK(&state->lock, cx);
|
681
|
+
if (table->generation == gen) {
|
682
|
+
JS_ASSERT(entry->keyAndFlags == 0);
|
683
|
+
} else {
|
684
|
+
entry = TO_ATOM_ENTRY(JS_DHashTableOperate(table, key,
|
685
|
+
JS_DHASH_ADD));
|
686
|
+
if (!entry)
|
687
|
+
goto failed_hash_add;
|
688
|
+
if (entry->keyAndFlags != 0) {
|
689
|
+
key = (JSString *)ATOM_ENTRY_KEY(entry);
|
690
|
+
goto finish;
|
691
|
+
}
|
692
|
+
++table->generation;
|
693
|
+
}
|
694
|
+
}
|
695
|
+
INIT_ATOM_ENTRY(entry, key);
|
696
|
+
JSFLATSTR_SET_ATOMIZED(key);
|
697
|
+
}
|
698
|
+
|
699
|
+
finish:
|
700
|
+
ADD_ATOM_ENTRY_FLAGS(entry, flags & (ATOM_PINNED | ATOM_INTERNED));
|
701
|
+
JS_ASSERT(JSSTRING_IS_ATOMIZED(key));
|
702
|
+
v = STRING_TO_JSVAL(key);
|
703
|
+
cx->weakRoots.lastAtom = v;
|
704
|
+
JS_UNLOCK(&state->lock, cx);
|
705
|
+
return (JSAtom *)v;
|
706
|
+
|
707
|
+
failed_hash_add:
|
708
|
+
JS_UNLOCK(&state->lock,cx);
|
709
|
+
JS_ReportOutOfMemory(cx);
|
710
|
+
return NULL;
|
711
|
+
}
|
712
|
+
|
713
|
+
JSAtom *
|
714
|
+
js_Atomize(JSContext *cx, const char *bytes, size_t length, uintN flags)
|
715
|
+
{
|
716
|
+
jschar *chars;
|
717
|
+
JSString str;
|
718
|
+
JSAtom *atom;
|
719
|
+
|
720
|
+
/*
|
721
|
+
* Avoiding the malloc in js_InflateString on shorter strings saves us
|
722
|
+
* over 20,000 malloc calls on mozilla browser startup. This compares to
|
723
|
+
* only 131 calls where the string is longer than a 31 char (net) buffer.
|
724
|
+
* The vast majority of atomized strings are already in the hashtable. So
|
725
|
+
* js_AtomizeString rarely has to copy the temp string we make.
|
726
|
+
*/
|
727
|
+
#define ATOMIZE_BUF_MAX 32
|
728
|
+
jschar inflated[ATOMIZE_BUF_MAX];
|
729
|
+
size_t inflatedLength = ATOMIZE_BUF_MAX - 1;
|
730
|
+
|
731
|
+
if (length < ATOMIZE_BUF_MAX) {
|
732
|
+
js_InflateStringToBuffer(cx, bytes, length, inflated, &inflatedLength);
|
733
|
+
inflated[inflatedLength] = 0;
|
734
|
+
chars = inflated;
|
735
|
+
} else {
|
736
|
+
inflatedLength = length;
|
737
|
+
chars = js_InflateString(cx, bytes, &inflatedLength);
|
738
|
+
if (!chars)
|
739
|
+
return NULL;
|
740
|
+
flags |= ATOM_NOCOPY;
|
741
|
+
}
|
742
|
+
|
743
|
+
JSFLATSTR_INIT(&str, (jschar *)chars, inflatedLength);
|
744
|
+
atom = js_AtomizeString(cx, &str, ATOM_TMPSTR | flags);
|
745
|
+
if (chars != inflated && str.u.chars)
|
746
|
+
JS_free(cx, chars);
|
747
|
+
return atom;
|
748
|
+
}
|
749
|
+
|
750
|
+
JSAtom *
|
751
|
+
js_AtomizeChars(JSContext *cx, const jschar *chars, size_t length, uintN flags)
|
752
|
+
{
|
753
|
+
JSString str;
|
754
|
+
|
755
|
+
JSFLATSTR_INIT(&str, (jschar *)chars, length);
|
756
|
+
return js_AtomizeString(cx, &str, ATOM_TMPSTR | flags);
|
757
|
+
}
|
758
|
+
|
759
|
+
JSAtom *
|
760
|
+
js_GetExistingStringAtom(JSContext *cx, const jschar *chars, size_t length)
|
761
|
+
{
|
762
|
+
JSString str, *str2;
|
763
|
+
JSAtomState *state;
|
764
|
+
JSDHashEntryHdr *hdr;
|
765
|
+
|
766
|
+
JSFLATSTR_INIT(&str, (jschar *)chars, length);
|
767
|
+
state = &cx->runtime->atomState;
|
768
|
+
|
769
|
+
JS_LOCK(&state->lock, cx);
|
770
|
+
hdr = JS_DHashTableOperate(&state->stringAtoms, &str, JS_DHASH_LOOKUP);
|
771
|
+
str2 = JS_DHASH_ENTRY_IS_BUSY(hdr)
|
772
|
+
? (JSString *)ATOM_ENTRY_KEY(TO_ATOM_ENTRY(hdr))
|
773
|
+
: NULL;
|
774
|
+
JS_UNLOCK(&state->lock, cx);
|
775
|
+
|
776
|
+
return str2 ? (JSAtom *)STRING_TO_JSVAL(str2) : NULL;
|
777
|
+
}
|
778
|
+
|
779
|
+
JSBool
|
780
|
+
js_AtomizePrimitiveValue(JSContext *cx, jsval v, JSAtom **atomp)
|
781
|
+
{
|
782
|
+
JSAtom *atom;
|
783
|
+
|
784
|
+
if (JSVAL_IS_STRING(v)) {
|
785
|
+
atom = js_AtomizeString(cx, JSVAL_TO_STRING(v), 0);
|
786
|
+
if (!atom)
|
787
|
+
return JS_FALSE;
|
788
|
+
} else if (JSVAL_IS_DOUBLE(v)) {
|
789
|
+
atom = js_AtomizeDouble(cx, *JSVAL_TO_DOUBLE(v));
|
790
|
+
if (!atom)
|
791
|
+
return JS_FALSE;
|
792
|
+
} else {
|
793
|
+
JS_ASSERT(JSVAL_IS_INT(v) || v == JSVAL_TRUE || v == JSVAL_FALSE ||
|
794
|
+
v == JSVAL_NULL || v == JSVAL_VOID);
|
795
|
+
atom = (JSAtom *)v;
|
796
|
+
}
|
797
|
+
*atomp = atom;
|
798
|
+
return JS_TRUE;
|
799
|
+
}
|
800
|
+
|
801
|
+
JSBool
|
802
|
+
js_ValueToStringId(JSContext *cx, jsval v, jsid *idp)
|
803
|
+
{
|
804
|
+
JSString *str;
|
805
|
+
JSAtom *atom;
|
806
|
+
|
807
|
+
/*
|
808
|
+
* Optimize for the common case where v is an already-atomized string. The
|
809
|
+
* comment in jsstr.h before the JSSTRING_SET_ATOMIZED macro's definition
|
810
|
+
* explains why this is thread-safe. The extra rooting via lastAtom (which
|
811
|
+
* would otherwise be done in js_js_AtomizeString) ensures the caller that
|
812
|
+
* the resulting id at is least weakly rooted.
|
813
|
+
*/
|
814
|
+
if (JSVAL_IS_STRING(v)) {
|
815
|
+
str = JSVAL_TO_STRING(v);
|
816
|
+
if (JSSTRING_IS_ATOMIZED(str)) {
|
817
|
+
cx->weakRoots.lastAtom = v;
|
818
|
+
*idp = ATOM_TO_JSID((JSAtom *) v);
|
819
|
+
return JS_TRUE;
|
820
|
+
}
|
821
|
+
} else {
|
822
|
+
str = js_ValueToString(cx, v);
|
823
|
+
if (!str)
|
824
|
+
return JS_FALSE;
|
825
|
+
}
|
826
|
+
atom = js_AtomizeString(cx, str, 0);
|
827
|
+
if (!atom)
|
828
|
+
return JS_FALSE;
|
829
|
+
*idp = ATOM_TO_JSID(atom);
|
830
|
+
return JS_TRUE;
|
831
|
+
}
|
832
|
+
|
833
|
+
#ifdef DEBUG
|
834
|
+
|
835
|
+
JS_STATIC_DLL_CALLBACK(JSDHashOperator)
|
836
|
+
atom_dumper(JSDHashTable *table, JSDHashEntryHdr *hdr,
|
837
|
+
uint32 number, void *arg)
|
838
|
+
{
|
839
|
+
JSAtomHashEntry *entry = TO_ATOM_ENTRY(hdr);
|
840
|
+
FILE *fp = (FILE *)arg;
|
841
|
+
void *key;
|
842
|
+
uintN flags;
|
843
|
+
|
844
|
+
fprintf(fp, "%3u %08x ", number, (uintN)entry->hdr.keyHash);
|
845
|
+
if (entry->keyAndFlags == 0) {
|
846
|
+
fputs("<uninitialized>", fp);
|
847
|
+
} else {
|
848
|
+
key = ATOM_ENTRY_KEY(entry);
|
849
|
+
if (IS_DOUBLE_TABLE(table)) {
|
850
|
+
fprintf(fp, "%.16g", *(jsdouble *)key);
|
851
|
+
} else {
|
852
|
+
JS_ASSERT(IS_STRING_TABLE(table));
|
853
|
+
js_FileEscapedString(fp, (JSString *)key, '"');
|
854
|
+
}
|
855
|
+
flags = ATOM_ENTRY_FLAGS(entry);
|
856
|
+
if (flags != 0) {
|
857
|
+
fputs((flags & (ATOM_PINNED | ATOM_INTERNED))
|
858
|
+
? " pinned | interned"
|
859
|
+
: (flags & ATOM_PINNED) ? " pinned" : " interned",
|
860
|
+
fp);
|
861
|
+
}
|
862
|
+
}
|
863
|
+
putc('\n', fp);
|
864
|
+
return JS_DHASH_NEXT;
|
865
|
+
}
|
866
|
+
|
867
|
+
JS_FRIEND_API(void)
|
868
|
+
js_DumpAtoms(JSContext *cx, FILE *fp)
|
869
|
+
{
|
870
|
+
JSAtomState *state = &cx->runtime->atomState;
|
871
|
+
|
872
|
+
fprintf(fp, "stringAtoms table contents:\n");
|
873
|
+
JS_DHashTableEnumerate(&state->stringAtoms, atom_dumper, fp);
|
874
|
+
#ifdef JS_DHASHMETER
|
875
|
+
JS_DHashTableDumpMeter(&state->stringAtoms, atom_dumper, fp);
|
876
|
+
#endif
|
877
|
+
putc('\n', fp);
|
878
|
+
|
879
|
+
fprintf(fp, "doubleAtoms table contents:\n");
|
880
|
+
JS_DHashTableEnumerate(&state->doubleAtoms, atom_dumper, fp);
|
881
|
+
#ifdef JS_DHASHMETER
|
882
|
+
JS_DHashTableDumpMeter(&state->doubleAtoms, atom_dumper, fp);
|
883
|
+
#endif
|
884
|
+
putc('\n', fp);
|
885
|
+
}
|
886
|
+
|
887
|
+
#endif
|
888
|
+
|
889
|
+
JS_STATIC_DLL_CALLBACK(JSHashNumber)
|
890
|
+
js_hash_atom_ptr(const void *key)
|
891
|
+
{
|
892
|
+
const JSAtom *atom = (const JSAtom *) key;
|
893
|
+
return ATOM_HASH(atom);
|
894
|
+
}
|
895
|
+
|
896
|
+
JS_STATIC_DLL_CALLBACK(void *)
|
897
|
+
js_alloc_temp_space(void *priv, size_t size)
|
898
|
+
{
|
899
|
+
JSContext *cx = (JSContext *) priv;
|
900
|
+
void *space;
|
901
|
+
|
902
|
+
JS_ARENA_ALLOCATE(space, &cx->tempPool, size);
|
903
|
+
if (!space)
|
904
|
+
js_ReportOutOfScriptQuota(cx);
|
905
|
+
return space;
|
906
|
+
}
|
907
|
+
|
908
|
+
JS_STATIC_DLL_CALLBACK(void)
|
909
|
+
js_free_temp_space(void *priv, void *item)
|
910
|
+
{
|
911
|
+
}
|
912
|
+
|
913
|
+
JS_STATIC_DLL_CALLBACK(JSHashEntry *)
|
914
|
+
js_alloc_temp_entry(void *priv, const void *key)
|
915
|
+
{
|
916
|
+
JSContext *cx = (JSContext *) priv;
|
917
|
+
JSAtomListElement *ale;
|
918
|
+
|
919
|
+
JS_ARENA_ALLOCATE_TYPE(ale, JSAtomListElement, &cx->tempPool);
|
920
|
+
if (!ale) {
|
921
|
+
js_ReportOutOfScriptQuota(cx);
|
922
|
+
return NULL;
|
923
|
+
}
|
924
|
+
return &ale->entry;
|
925
|
+
}
|
926
|
+
|
927
|
+
JS_STATIC_DLL_CALLBACK(void)
|
928
|
+
js_free_temp_entry(void *priv, JSHashEntry *he, uintN flag)
|
929
|
+
{
|
930
|
+
}
|
931
|
+
|
932
|
+
static JSHashAllocOps temp_alloc_ops = {
|
933
|
+
js_alloc_temp_space, js_free_temp_space,
|
934
|
+
js_alloc_temp_entry, js_free_temp_entry
|
935
|
+
};
|
936
|
+
|
937
|
+
JSAtomListElement *
|
938
|
+
js_IndexAtom(JSContext *cx, JSAtom *atom, JSAtomList *al)
|
939
|
+
{
|
940
|
+
JSAtomListElement *ale, *ale2, *next;
|
941
|
+
JSHashEntry **hep;
|
942
|
+
|
943
|
+
ATOM_LIST_LOOKUP(ale, hep, al, atom);
|
944
|
+
if (!ale) {
|
945
|
+
if (al->count < 10) {
|
946
|
+
/* Few enough for linear search, no hash table needed. */
|
947
|
+
JS_ASSERT(!al->table);
|
948
|
+
ale = (JSAtomListElement *)js_alloc_temp_entry(cx, atom);
|
949
|
+
if (!ale)
|
950
|
+
return NULL;
|
951
|
+
ALE_SET_ATOM(ale, atom);
|
952
|
+
ale->entry.next = al->list;
|
953
|
+
al->list = &ale->entry;
|
954
|
+
} else {
|
955
|
+
/* We want to hash. Have we already made a hash table? */
|
956
|
+
if (!al->table) {
|
957
|
+
/* No hash table yet, so hep had better be null! */
|
958
|
+
JS_ASSERT(!hep);
|
959
|
+
al->table = JS_NewHashTable(al->count + 1, js_hash_atom_ptr,
|
960
|
+
JS_CompareValues, JS_CompareValues,
|
961
|
+
&temp_alloc_ops, cx);
|
962
|
+
if (!al->table)
|
963
|
+
return NULL;
|
964
|
+
|
965
|
+
/*
|
966
|
+
* Set ht->nentries explicitly, because we are moving entries
|
967
|
+
* from al to ht, not calling JS_HashTable(Raw|)Add.
|
968
|
+
*/
|
969
|
+
al->table->nentries = al->count;
|
970
|
+
|
971
|
+
/* Insert each ale on al->list into the new hash table. */
|
972
|
+
for (ale2 = (JSAtomListElement *)al->list; ale2; ale2 = next) {
|
973
|
+
next = ALE_NEXT(ale2);
|
974
|
+
ale2->entry.keyHash = ATOM_HASH(ALE_ATOM(ale2));
|
975
|
+
hep = JS_HashTableRawLookup(al->table, ale2->entry.keyHash,
|
976
|
+
ale2->entry.key);
|
977
|
+
ale2->entry.next = *hep;
|
978
|
+
*hep = &ale2->entry;
|
979
|
+
}
|
980
|
+
al->list = NULL;
|
981
|
+
|
982
|
+
/* Set hep for insertion of atom's ale, immediately below. */
|
983
|
+
hep = JS_HashTableRawLookup(al->table, ATOM_HASH(atom), atom);
|
984
|
+
}
|
985
|
+
|
986
|
+
/* Finally, add an entry for atom into the hash bucket at hep. */
|
987
|
+
ale = (JSAtomListElement *)
|
988
|
+
JS_HashTableRawAdd(al->table, hep, ATOM_HASH(atom), atom,
|
989
|
+
NULL);
|
990
|
+
if (!ale)
|
991
|
+
return NULL;
|
992
|
+
}
|
993
|
+
|
994
|
+
ALE_SET_INDEX(ale, al->count++);
|
995
|
+
}
|
996
|
+
return ale;
|
997
|
+
}
|
998
|
+
|
999
|
+
JS_STATIC_DLL_CALLBACK(intN)
|
1000
|
+
js_map_atom(JSHashEntry *he, intN i, void *arg)
|
1001
|
+
{
|
1002
|
+
JSAtomListElement *ale = (JSAtomListElement *)he;
|
1003
|
+
JSAtom **vector = (JSAtom **) arg;
|
1004
|
+
|
1005
|
+
vector[ALE_INDEX(ale)] = ALE_ATOM(ale);
|
1006
|
+
return HT_ENUMERATE_NEXT;
|
1007
|
+
}
|
1008
|
+
|
1009
|
+
#ifdef DEBUG
|
1010
|
+
static jsrefcount js_atom_map_count;
|
1011
|
+
static jsrefcount js_atom_map_hash_table_count;
|
1012
|
+
#endif
|
1013
|
+
|
1014
|
+
void
|
1015
|
+
js_InitAtomMap(JSContext *cx, JSAtomMap *map, JSAtomList *al)
|
1016
|
+
{
|
1017
|
+
JSAtom **vector;
|
1018
|
+
JSAtomListElement *ale;
|
1019
|
+
uint32 count;
|
1020
|
+
|
1021
|
+
/* Map length must already be initialized. */
|
1022
|
+
JS_ASSERT(al->count == map->length);
|
1023
|
+
#ifdef DEBUG
|
1024
|
+
JS_ATOMIC_INCREMENT(&js_atom_map_count);
|
1025
|
+
#endif
|
1026
|
+
ale = (JSAtomListElement *)al->list;
|
1027
|
+
if (!ale && !al->table) {
|
1028
|
+
JS_ASSERT(!map->vector);
|
1029
|
+
return;
|
1030
|
+
}
|
1031
|
+
|
1032
|
+
count = al->count;
|
1033
|
+
vector = map->vector;
|
1034
|
+
if (al->table) {
|
1035
|
+
#ifdef DEBUG
|
1036
|
+
JS_ATOMIC_INCREMENT(&js_atom_map_hash_table_count);
|
1037
|
+
#endif
|
1038
|
+
JS_HashTableEnumerateEntries(al->table, js_map_atom, vector);
|
1039
|
+
} else {
|
1040
|
+
do {
|
1041
|
+
vector[ALE_INDEX(ale)] = ALE_ATOM(ale);
|
1042
|
+
} while ((ale = ALE_NEXT(ale)) != NULL);
|
1043
|
+
}
|
1044
|
+
ATOM_LIST_INIT(al);
|
1045
|
+
}
|