jbarnette-johnson 1.0.0.200806240111 → 1.0.0.200807291507
Sign up to get free protection for your applications and to get access to all the features.
- 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,183 @@
|
|
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 jsregexp_h___
|
41
|
+
#define jsregexp_h___
|
42
|
+
/*
|
43
|
+
* JS regular expression interface.
|
44
|
+
*/
|
45
|
+
#include <stddef.h>
|
46
|
+
#include "jspubtd.h"
|
47
|
+
#include "jsstr.h"
|
48
|
+
|
49
|
+
#ifdef JS_THREADSAFE
|
50
|
+
#include "jsdhash.h"
|
51
|
+
#endif
|
52
|
+
|
53
|
+
JS_BEGIN_EXTERN_C
|
54
|
+
|
55
|
+
struct JSRegExpStatics {
|
56
|
+
JSString *input; /* input string to match (perl $_, GC root) */
|
57
|
+
JSBool multiline; /* whether input contains newlines (perl $*) */
|
58
|
+
uint16 parenCount; /* number of valid elements in parens[] */
|
59
|
+
uint16 moreLength; /* number of allocated elements in moreParens */
|
60
|
+
JSSubString parens[9]; /* last set of parens matched (perl $1, $2) */
|
61
|
+
JSSubString *moreParens; /* null or realloc'd vector for $10, etc. */
|
62
|
+
JSSubString lastMatch; /* last string matched (perl $&) */
|
63
|
+
JSSubString lastParen; /* last paren matched (perl $+) */
|
64
|
+
JSSubString leftContext; /* input to left of last match (perl $`) */
|
65
|
+
JSSubString rightContext; /* input to right of last match (perl $') */
|
66
|
+
};
|
67
|
+
|
68
|
+
/*
|
69
|
+
* This struct holds a bitmap representation of a class from a regexp.
|
70
|
+
* There's a list of these referenced by the classList field in the JSRegExp
|
71
|
+
* struct below. The initial state has startIndex set to the offset in the
|
72
|
+
* original regexp source of the beginning of the class contents. The first
|
73
|
+
* use of the class converts the source representation into a bitmap.
|
74
|
+
*
|
75
|
+
*/
|
76
|
+
typedef struct RECharSet {
|
77
|
+
JSPackedBool converted;
|
78
|
+
JSPackedBool sense;
|
79
|
+
uint16 length;
|
80
|
+
union {
|
81
|
+
uint8 *bits;
|
82
|
+
struct {
|
83
|
+
size_t startIndex;
|
84
|
+
size_t length;
|
85
|
+
} src;
|
86
|
+
} u;
|
87
|
+
} RECharSet;
|
88
|
+
|
89
|
+
/*
|
90
|
+
* This macro is safe because moreParens is guaranteed to be allocated and big
|
91
|
+
* enough to hold parenCount, or else be null when parenCount is 0.
|
92
|
+
*/
|
93
|
+
#define REGEXP_PAREN_SUBSTRING(res, num) \
|
94
|
+
(((jsuint)(num) < (jsuint)(res)->parenCount) \
|
95
|
+
? ((jsuint)(num) < 9) \
|
96
|
+
? &(res)->parens[num] \
|
97
|
+
: &(res)->moreParens[(num) - 9] \
|
98
|
+
: &js_EmptySubString)
|
99
|
+
|
100
|
+
typedef struct RENode RENode;
|
101
|
+
|
102
|
+
struct JSRegExp {
|
103
|
+
jsrefcount nrefs; /* reference count */
|
104
|
+
uint16 flags; /* flags, see jsapi.h's JSREG_* defines */
|
105
|
+
size_t parenCount; /* number of parenthesized submatches */
|
106
|
+
size_t classCount; /* count [...] bitmaps */
|
107
|
+
RECharSet *classList; /* list of [...] bitmaps */
|
108
|
+
JSString *source; /* locked source string, sans // */
|
109
|
+
jsbytecode program[1]; /* regular expression bytecode */
|
110
|
+
};
|
111
|
+
|
112
|
+
extern JSRegExp *
|
113
|
+
js_NewRegExp(JSContext *cx, JSTokenStream *ts,
|
114
|
+
JSString *str, uintN flags, JSBool flat);
|
115
|
+
|
116
|
+
extern JSRegExp *
|
117
|
+
js_NewRegExpOpt(JSContext *cx, JSString *str, JSString *opt, JSBool flat);
|
118
|
+
|
119
|
+
#define HOLD_REGEXP(cx, re) JS_ATOMIC_INCREMENT(&(re)->nrefs)
|
120
|
+
#define DROP_REGEXP(cx, re) js_DestroyRegExp(cx, re)
|
121
|
+
|
122
|
+
extern void
|
123
|
+
js_DestroyRegExp(JSContext *cx, JSRegExp *re);
|
124
|
+
|
125
|
+
/*
|
126
|
+
* Execute re on input str at *indexp, returning null in *rval on mismatch.
|
127
|
+
* On match, return true if test is true, otherwise return an array object.
|
128
|
+
* Update *indexp and cx->regExpStatics always on match.
|
129
|
+
*/
|
130
|
+
extern JSBool
|
131
|
+
js_ExecuteRegExp(JSContext *cx, JSRegExp *re, JSString *str, size_t *indexp,
|
132
|
+
JSBool test, jsval *rval);
|
133
|
+
|
134
|
+
/*
|
135
|
+
* These two add and remove GC roots, respectively, so their calls must be
|
136
|
+
* well-ordered.
|
137
|
+
*/
|
138
|
+
extern JSBool
|
139
|
+
js_InitRegExpStatics(JSContext *cx, JSRegExpStatics *res);
|
140
|
+
|
141
|
+
extern void
|
142
|
+
js_FreeRegExpStatics(JSContext *cx, JSRegExpStatics *res);
|
143
|
+
|
144
|
+
#define JSVAL_IS_REGEXP(cx, v) \
|
145
|
+
(JSVAL_IS_OBJECT(v) && JSVAL_TO_OBJECT(v) && \
|
146
|
+
OBJ_GET_CLASS(cx, JSVAL_TO_OBJECT(v)) == &js_RegExpClass)
|
147
|
+
|
148
|
+
extern JSClass js_RegExpClass;
|
149
|
+
|
150
|
+
extern JSObject *
|
151
|
+
js_InitRegExpClass(JSContext *cx, JSObject *obj);
|
152
|
+
|
153
|
+
/*
|
154
|
+
* Export js_regexp_toString to the decompiler.
|
155
|
+
*/
|
156
|
+
extern JSBool
|
157
|
+
js_regexp_toString(JSContext *cx, JSObject *obj, jsval *vp);
|
158
|
+
|
159
|
+
/*
|
160
|
+
* Create, serialize/deserialize, or clone a RegExp object.
|
161
|
+
*/
|
162
|
+
extern JSObject *
|
163
|
+
js_NewRegExpObject(JSContext *cx, JSTokenStream *ts,
|
164
|
+
jschar *chars, size_t length, uintN flags);
|
165
|
+
|
166
|
+
extern JSBool
|
167
|
+
js_XDRRegExp(JSXDRState *xdr, JSObject **objp);
|
168
|
+
|
169
|
+
extern JSObject *
|
170
|
+
js_CloneRegExpObject(JSContext *cx, JSObject *obj, JSObject *parent);
|
171
|
+
|
172
|
+
/*
|
173
|
+
* Get and set the per-object (clone or clone-parent) lastIndex slot.
|
174
|
+
*/
|
175
|
+
extern JSBool
|
176
|
+
js_GetLastIndex(JSContext *cx, JSObject *obj, jsdouble *lastIndex);
|
177
|
+
|
178
|
+
extern JSBool
|
179
|
+
js_SetLastIndex(JSContext *cx, JSObject *obj, jsdouble lastIndex);
|
180
|
+
|
181
|
+
JS_END_EXTERN_C
|
182
|
+
|
183
|
+
#endif /* jsregexp_h___ */
|
@@ -0,0 +1,145 @@
|
|
1
|
+
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2
|
+
* vim: set ts=8 sw=4 et tw=0 ft=C:
|
3
|
+
*
|
4
|
+
* ***** BEGIN LICENSE BLOCK *****
|
5
|
+
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
6
|
+
*
|
7
|
+
* The contents of this file are subject to the Mozilla Public License Version
|
8
|
+
* 1.1 (the "license"); you may not use this file except in compliance with
|
9
|
+
* the License. You may obtain a copy of the License at
|
10
|
+
* http://www.mozilla.org/MPL/
|
11
|
+
*
|
12
|
+
* Software distributed under the License is distributed on an "as is" basis,
|
13
|
+
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
14
|
+
* for the specific language governing rights and limitations under the
|
15
|
+
* License.
|
16
|
+
*
|
17
|
+
* The Original Code is Mozilla Communicator client code, released
|
18
|
+
* March 31, 1998.
|
19
|
+
*
|
20
|
+
* The Initial Developer of the Original Code is
|
21
|
+
* Netscape Communications Corporation.
|
22
|
+
* Portions created by the Initial Developer are Copyright (C) 1998
|
23
|
+
* the Initial Developer. All Rights Reserved.
|
24
|
+
*
|
25
|
+
* Contributor(s):
|
26
|
+
*
|
27
|
+
* Alternatively, the contentsof this file are subject to the Mozilla Public License Version
|
28
|
+
* 1.1 (the "license"); you may not use this file except in compliance with
|
29
|
+
* the License. You may obtain a copy of thter (the "lgpl"),
|
30
|
+
* in which case the provisions of the GPL or the LGPL are applicable instead
|
31
|
+
* of those above. If you wish to allow use of your version of this file only
|
32
|
+
* under the terms of either the GPL or the LGPL, and not to allow others to
|
33
|
+
* use your version of this file under the terms of the MPL, indicate your
|
34
|
+
* decision by deleting the provisions above and replace them with the notice
|
35
|
+
* and other provisions required by the GPL or the LGPL. If you do not delete
|
36
|
+
* the provisions above, a recipient may use your version of this file under
|
37
|
+
* the terms of any one of the MPL, the GPL or the LGPL.
|
38
|
+
*
|
39
|
+
* ***** END LICENSE BLOCK ***** */
|
40
|
+
|
41
|
+
|
42
|
+
/* Note : contiguity of 'simple opcodes' is important for SimpleMatch() */
|
43
|
+
|
44
|
+
/* match rest of input against rest of r.e. */
|
45
|
+
REOP_DEF(REOP_EMPTY, "empty")
|
46
|
+
/* beginning of input (or line if multiline) */
|
47
|
+
REOP_DEF(REOP_BOL, "bol")
|
48
|
+
/* end of input (or line if multiline) */
|
49
|
+
REOP_DEF(REOP_EOL, "eol")
|
50
|
+
/* match "" at word boundary */
|
51
|
+
REOP_DEF(REOP_WBDRY, "wbdry")
|
52
|
+
/* match "" at word non-boundary */
|
53
|
+
REOP_DEF(REOP_WNONBDRY, "wnonbdry")
|
54
|
+
/* stands for any character */
|
55
|
+
REOP_DEF(REOP_DOT, "dot")
|
56
|
+
/* match a digit char: [0-9] */
|
57
|
+
REOP_DEF(REOP_DIGIT, "digit")
|
58
|
+
/* match a non-digit char: [^0-9] */
|
59
|
+
REOP_DEF(REOP_NONDIGIT, "nondigit")
|
60
|
+
/* match an alphanumeric char: [0-9a-z_A-Z] */
|
61
|
+
REOP_DEF(REOP_ALNUM, "alnum")
|
62
|
+
/* match a non-alphanumeric char: [^0-9a-z_A-Z] */
|
63
|
+
REOP_DEF(REOP_NONALNUM, "nonalnum")
|
64
|
+
/* match a whitespace char */
|
65
|
+
REOP_DEF(REOP_SPACE, "space")
|
66
|
+
/* match a non-whitespace char */
|
67
|
+
REOP_DEF(REOP_NONSPACE, "nonspace")
|
68
|
+
/* back-reference (e.g., \1) to a parenthetical */
|
69
|
+
REOP_DEF(REOP_BACKREF, "backref")
|
70
|
+
/* match a flat string */
|
71
|
+
REOP_DEF(REOP_FLAT, "flat")
|
72
|
+
/* match a single char */
|
73
|
+
REOP_DEF(REOP_FLAT1, "flat1")
|
74
|
+
/* case-independent REOP_FLAT */
|
75
|
+
REOP_DEF(REOP_FLATi, "flati")
|
76
|
+
/* case-independent REOP_FLAT1 */
|
77
|
+
REOP_DEF(REOP_FLAT1i, "flat1i")
|
78
|
+
/* single Unicode char */
|
79
|
+
REOP_DEF(REOP_UCFLAT1, "ucflat1")
|
80
|
+
/* case-independent REOP_UCFLAT1 */
|
81
|
+
REOP_DEF(REOP_UCFLAT1i, "ucflat1i")
|
82
|
+
/* flat Unicode string; len immediate counts chars */
|
83
|
+
REOP_DEF(REOP_UCFLAT, "ucflat")
|
84
|
+
/* case-independent REOP_UCFLAT */
|
85
|
+
REOP_DEF(REOP_UCFLATi, "ucflati")
|
86
|
+
/* character class with index */
|
87
|
+
REOP_DEF(REOP_CLASS, "class")
|
88
|
+
/* negated character class with index */
|
89
|
+
REOP_DEF(REOP_NCLASS, "nclass")
|
90
|
+
|
91
|
+
/* NCLASS is considered to be the last "simple" op-code */
|
92
|
+
|
93
|
+
|
94
|
+
/* alternative subexpressions in kid and next */
|
95
|
+
REOP_DEF(REOP_ALT, "alt")
|
96
|
+
/* quantified atom: atom{1,2} */
|
97
|
+
REOP_DEF(REOP_QUANT, "quant")
|
98
|
+
/* zero or more occurrences of kid */
|
99
|
+
REOP_DEF(REOP_STAR, "star")
|
100
|
+
/* one or more occurrences of kid */
|
101
|
+
REOP_DEF(REOP_PLUS, "plus")
|
102
|
+
/* optional subexpression in kid */
|
103
|
+
REOP_DEF(REOP_OPT, "opt")
|
104
|
+
/* left paren bytecode: kid is u.num'th sub-regexp */
|
105
|
+
REOP_DEF(REOP_LPAREN, "lparen")
|
106
|
+
/* right paren bytecode */
|
107
|
+
REOP_DEF(REOP_RPAREN, "rparen")
|
108
|
+
/* for deoptimized closure loops */
|
109
|
+
REOP_DEF(REOP_JUMP, "jump")
|
110
|
+
/* optimize .* to use a single opcode */
|
111
|
+
REOP_DEF(REOP_DOTSTAR, "dotstar")
|
112
|
+
/* non-capturing version of REOP_LPAREN */
|
113
|
+
REOP_DEF(REOP_LPARENNON, "lparennon")
|
114
|
+
/* zero width positive lookahead assertion */
|
115
|
+
REOP_DEF(REOP_ASSERT, "assert")
|
116
|
+
/* zero width negative lookahead assertion */
|
117
|
+
REOP_DEF(REOP_ASSERT_NOT, "assert_not")
|
118
|
+
/* sentinel at end of assertion child */
|
119
|
+
REOP_DEF(REOP_ASSERTTEST, "asserttest")
|
120
|
+
/* sentinel at end of !assertion child */
|
121
|
+
REOP_DEF(REOP_ASSERTNOTTEST, "assertnottest")
|
122
|
+
/* non-greedy version of * */
|
123
|
+
REOP_DEF(REOP_MINIMALSTAR, "minimalstar")
|
124
|
+
/* non-greedy version of + */
|
125
|
+
REOP_DEF(REOP_MINIMALPLUS, "minimalplus")
|
126
|
+
/* non-greedy version of ? */
|
127
|
+
REOP_DEF(REOP_MINIMALOPT, "minimalopt")
|
128
|
+
/* non-greedy version of {} */
|
129
|
+
REOP_DEF(REOP_MINIMALQUANT, "minimalquant")
|
130
|
+
/* sentinel at end of quantifier child */
|
131
|
+
REOP_DEF(REOP_ENDCHILD, "endchild")
|
132
|
+
/* directs execution of greedy quantifier */
|
133
|
+
REOP_DEF(REOP_REPEAT, "repeat")
|
134
|
+
/* directs execution of non-greedy quantifier */
|
135
|
+
REOP_DEF(REOP_MINIMALREPEAT, "minimalrepeat")
|
136
|
+
/* prerequisite for ALT, either of two chars */
|
137
|
+
REOP_DEF(REOP_ALTPREREQ, "altprereq")
|
138
|
+
/* prerequisite for ALT, a char or a class */
|
139
|
+
REOP_DEF(REOP_ALTPREREQ2, "altprereq2")
|
140
|
+
/* end of final alternate */
|
141
|
+
REOP_DEF(REOP_ENDALT, "endalt")
|
142
|
+
/* concatenation of terms (parse time only) */
|
143
|
+
REOP_DEF(REOP_CONCAT, "concat")
|
144
|
+
/* end of expression */
|
145
|
+
REOP_DEF(REOP_END, "end")
|
@@ -0,0 +1,2003 @@
|
|
1
|
+
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2
|
+
* vim: set sw=4 ts=8 et tw=78:
|
3
|
+
*
|
4
|
+
* ***** BEGIN LICENSE BLOCK *****
|
5
|
+
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
6
|
+
*
|
7
|
+
* The contents of this file are subject to the Mozilla Public License Version
|
8
|
+
* 1.1 (the "License"); you may not use this file except in compliance with
|
9
|
+
* the License. You may obtain a copy of the License at
|
10
|
+
* http://www.mozilla.org/MPL/
|
11
|
+
*
|
12
|
+
* Software distributed under the License is distributed on an "AS IS" basis,
|
13
|
+
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
14
|
+
* for the specific language governing rights and limitations under the
|
15
|
+
* License.
|
16
|
+
*
|
17
|
+
* The Original Code is Mozilla Communicator client code, released
|
18
|
+
* March 31, 1998.
|
19
|
+
*
|
20
|
+
* The Initial Developer of the Original Code is
|
21
|
+
* Netscape Communications Corporation.
|
22
|
+
* Portions created by the Initial Developer are Copyright (C) 1998
|
23
|
+
* the Initial Developer. All Rights Reserved.
|
24
|
+
*
|
25
|
+
* Contributor(s):
|
26
|
+
*
|
27
|
+
* Alternatively, the contents of this file may be used under the terms of
|
28
|
+
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
29
|
+
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
30
|
+
* in which case the provisions of the GPL or the LGPL are applicable instead
|
31
|
+
* of those above. If you wish to allow use of your version of this file only
|
32
|
+
* under the terms of either the GPL or the LGPL, and not to allow others to
|
33
|
+
* use your version of this file under the terms of the MPL, indicate your
|
34
|
+
* decision by deleting the provisions above and replace them with the notice
|
35
|
+
* and other provisions required by the GPL or the LGPL. If you do not delete
|
36
|
+
* the provisions above, a recipient may use your version of this file under
|
37
|
+
* the terms of any one of the MPL, the GPL or the LGPL.
|
38
|
+
*
|
39
|
+
* ***** END LICENSE BLOCK ***** */
|
40
|
+
|
41
|
+
/*
|
42
|
+
* JS lexical scanner.
|
43
|
+
*/
|
44
|
+
#include "jsstddef.h"
|
45
|
+
#include <stdio.h> /* first to avoid trouble on some systems */
|
46
|
+
#include <errno.h>
|
47
|
+
#include <limits.h>
|
48
|
+
#include <math.h>
|
49
|
+
#ifdef HAVE_MEMORY_H
|
50
|
+
#include <memory.h>
|
51
|
+
#endif
|
52
|
+
#include <stdarg.h>
|
53
|
+
#include <stdlib.h>
|
54
|
+
#include <string.h>
|
55
|
+
#include "jstypes.h"
|
56
|
+
#include "jsarena.h" /* Added by JSIFY */
|
57
|
+
#include "jsutil.h" /* Added by JSIFY */
|
58
|
+
#include "jsdtoa.h"
|
59
|
+
#include "jsprf.h"
|
60
|
+
#include "jsapi.h"
|
61
|
+
#include "jsatom.h"
|
62
|
+
#include "jscntxt.h"
|
63
|
+
#include "jsconfig.h"
|
64
|
+
#include "jsemit.h"
|
65
|
+
#include "jsexn.h"
|
66
|
+
#include "jsnum.h"
|
67
|
+
#include "jsopcode.h"
|
68
|
+
#include "jsparse.h"
|
69
|
+
#include "jsregexp.h"
|
70
|
+
#include "jsscan.h"
|
71
|
+
#include "jsscript.h"
|
72
|
+
|
73
|
+
#if JS_HAS_XML_SUPPORT
|
74
|
+
#include "jsxml.h"
|
75
|
+
#endif
|
76
|
+
|
77
|
+
#define JS_KEYWORD(keyword, type, op, version) \
|
78
|
+
const char js_##keyword##_str[] = #keyword;
|
79
|
+
#include "jskeyword.tbl"
|
80
|
+
#undef JS_KEYWORD
|
81
|
+
|
82
|
+
struct keyword {
|
83
|
+
const char *chars; /* C string with keyword text */
|
84
|
+
JSTokenType tokentype; /* JSTokenType */
|
85
|
+
JSOp op; /* JSOp */
|
86
|
+
JSVersion version; /* JSVersion */
|
87
|
+
};
|
88
|
+
|
89
|
+
static const struct keyword keyword_defs[] = {
|
90
|
+
#define JS_KEYWORD(keyword, type, op, version) \
|
91
|
+
{js_##keyword##_str, type, op, version},
|
92
|
+
#include "jskeyword.tbl"
|
93
|
+
#undef JS_KEYWORD
|
94
|
+
};
|
95
|
+
|
96
|
+
#define KEYWORD_COUNT JS_ARRAY_LENGTH(keyword_defs)
|
97
|
+
|
98
|
+
static const struct keyword *
|
99
|
+
FindKeyword(const jschar *s, size_t length)
|
100
|
+
{
|
101
|
+
register size_t i;
|
102
|
+
const struct keyword *kw;
|
103
|
+
const char *chars;
|
104
|
+
|
105
|
+
JS_ASSERT(length != 0);
|
106
|
+
|
107
|
+
#define JSKW_LENGTH() length
|
108
|
+
#define JSKW_AT(column) s[column]
|
109
|
+
#define JSKW_GOT_MATCH(index) i = (index); goto got_match;
|
110
|
+
#define JSKW_TEST_GUESS(index) i = (index); goto test_guess;
|
111
|
+
#define JSKW_NO_MATCH() goto no_match;
|
112
|
+
#include "jsautokw.h"
|
113
|
+
#undef JSKW_NO_MATCH
|
114
|
+
#undef JSKW_TEST_GUESS
|
115
|
+
#undef JSKW_GOT_MATCH
|
116
|
+
#undef JSKW_AT
|
117
|
+
#undef JSKW_LENGTH
|
118
|
+
|
119
|
+
got_match:
|
120
|
+
return &keyword_defs[i];
|
121
|
+
|
122
|
+
test_guess:
|
123
|
+
kw = &keyword_defs[i];
|
124
|
+
chars = kw->chars;
|
125
|
+
do {
|
126
|
+
if (*s++ != (unsigned char)(*chars++))
|
127
|
+
goto no_match;
|
128
|
+
} while (--length != 0);
|
129
|
+
return kw;
|
130
|
+
|
131
|
+
no_match:
|
132
|
+
return NULL;
|
133
|
+
}
|
134
|
+
|
135
|
+
JSTokenType
|
136
|
+
js_CheckKeyword(const jschar *str, size_t length)
|
137
|
+
{
|
138
|
+
const struct keyword *kw;
|
139
|
+
|
140
|
+
JS_ASSERT(length != 0);
|
141
|
+
kw = FindKeyword(str, length);
|
142
|
+
return kw ? kw->tokentype : TOK_EOF;
|
143
|
+
}
|
144
|
+
|
145
|
+
JS_FRIEND_API(void)
|
146
|
+
js_MapKeywords(void (*mapfun)(const char *))
|
147
|
+
{
|
148
|
+
size_t i;
|
149
|
+
|
150
|
+
for (i = 0; i != KEYWORD_COUNT; ++i)
|
151
|
+
mapfun(keyword_defs[i].chars);
|
152
|
+
}
|
153
|
+
|
154
|
+
JSBool
|
155
|
+
js_IsIdentifier(JSString *str)
|
156
|
+
{
|
157
|
+
size_t length;
|
158
|
+
jschar c, *chars, *end;
|
159
|
+
|
160
|
+
JSSTRING_CHARS_AND_LENGTH(str, chars, length);
|
161
|
+
if (length == 0)
|
162
|
+
return JS_FALSE;
|
163
|
+
c = *chars;
|
164
|
+
if (!JS_ISIDSTART(c))
|
165
|
+
return JS_FALSE;
|
166
|
+
end = chars + length;
|
167
|
+
while (++chars != end) {
|
168
|
+
c = *chars;
|
169
|
+
if (!JS_ISIDENT(c))
|
170
|
+
return JS_FALSE;
|
171
|
+
}
|
172
|
+
return JS_TRUE;
|
173
|
+
}
|
174
|
+
|
175
|
+
#define TBMIN 64
|
176
|
+
|
177
|
+
static JSBool
|
178
|
+
GrowTokenBuf(JSStringBuffer *sb, size_t newlength)
|
179
|
+
{
|
180
|
+
JSContext *cx;
|
181
|
+
jschar *base;
|
182
|
+
ptrdiff_t offset, length;
|
183
|
+
size_t tbsize;
|
184
|
+
JSArenaPool *pool;
|
185
|
+
|
186
|
+
cx = (JSContext*) sb->data;
|
187
|
+
base = sb->base;
|
188
|
+
offset = PTRDIFF(sb->ptr, base, jschar);
|
189
|
+
pool = &cx->tempPool;
|
190
|
+
if (!base) {
|
191
|
+
tbsize = TBMIN * sizeof(jschar);
|
192
|
+
length = TBMIN - 1;
|
193
|
+
JS_ARENA_ALLOCATE_CAST(base, jschar *, pool, tbsize);
|
194
|
+
} else {
|
195
|
+
length = PTRDIFF(sb->limit, base, jschar);
|
196
|
+
if ((size_t)length >= ~(size_t)0 / sizeof(jschar)) {
|
197
|
+
base = NULL;
|
198
|
+
} else {
|
199
|
+
tbsize = (length + 1) * sizeof(jschar);
|
200
|
+
length += length + 1;
|
201
|
+
JS_ARENA_GROW_CAST(base, jschar *, pool, tbsize, tbsize);
|
202
|
+
}
|
203
|
+
}
|
204
|
+
if (!base) {
|
205
|
+
js_ReportOutOfScriptQuota(cx);
|
206
|
+
sb->base = STRING_BUFFER_ERROR_BASE;
|
207
|
+
return JS_FALSE;
|
208
|
+
}
|
209
|
+
sb->base = base;
|
210
|
+
sb->limit = base + length;
|
211
|
+
sb->ptr = base + offset;
|
212
|
+
return JS_TRUE;
|
213
|
+
}
|
214
|
+
|
215
|
+
JSBool
|
216
|
+
js_InitTokenStream(JSContext *cx, JSTokenStream *ts,
|
217
|
+
const jschar *base, size_t length,
|
218
|
+
FILE *fp, const char *filename, uintN lineno)
|
219
|
+
{
|
220
|
+
jschar *buf;
|
221
|
+
size_t nb;
|
222
|
+
|
223
|
+
JS_ASSERT_IF(fp, !base);
|
224
|
+
JS_ASSERT_IF(!base, length == 0);
|
225
|
+
nb = fp
|
226
|
+
? 2 * JS_LINE_LIMIT * sizeof(jschar)
|
227
|
+
: JS_LINE_LIMIT * sizeof(jschar);
|
228
|
+
JS_ARENA_ALLOCATE_CAST(buf, jschar *, &cx->tempPool, nb);
|
229
|
+
if (!buf) {
|
230
|
+
js_ReportOutOfScriptQuota(cx);
|
231
|
+
return JS_FALSE;
|
232
|
+
}
|
233
|
+
memset(buf, 0, nb);
|
234
|
+
memset(ts, 0, sizeof(*ts));
|
235
|
+
ts->filename = filename;
|
236
|
+
ts->lineno = lineno;
|
237
|
+
ts->linebuf.base = ts->linebuf.limit = ts->linebuf.ptr = buf;
|
238
|
+
if (fp) {
|
239
|
+
ts->file = fp;
|
240
|
+
ts->userbuf.base = buf + JS_LINE_LIMIT;
|
241
|
+
ts->userbuf.ptr = ts->userbuf.limit = ts->userbuf.base + JS_LINE_LIMIT;
|
242
|
+
} else {
|
243
|
+
ts->userbuf.base = (jschar *)base;
|
244
|
+
ts->userbuf.limit = (jschar *)base + length;
|
245
|
+
ts->userbuf.ptr = (jschar *)base;
|
246
|
+
}
|
247
|
+
ts->tokenbuf.grow = GrowTokenBuf;
|
248
|
+
ts->tokenbuf.data = cx;
|
249
|
+
ts->listener = cx->debugHooks->sourceHandler;
|
250
|
+
ts->listenerData = cx->debugHooks->sourceHandlerData;
|
251
|
+
return JS_TRUE;
|
252
|
+
}
|
253
|
+
|
254
|
+
void
|
255
|
+
js_CloseTokenStream(JSContext *cx, JSTokenStream *ts)
|
256
|
+
{
|
257
|
+
if (ts->flags & TSF_OWNFILENAME)
|
258
|
+
JS_free(cx, (void *) ts->filename);
|
259
|
+
}
|
260
|
+
|
261
|
+
JS_FRIEND_API(int)
|
262
|
+
js_fgets(char *buf, int size, FILE *file)
|
263
|
+
{
|
264
|
+
int n, i, c;
|
265
|
+
JSBool crflag;
|
266
|
+
|
267
|
+
n = size - 1;
|
268
|
+
if (n < 0)
|
269
|
+
return -1;
|
270
|
+
|
271
|
+
crflag = JS_FALSE;
|
272
|
+
for (i = 0; i < n && (c = getc(file)) != EOF; i++) {
|
273
|
+
buf[i] = c;
|
274
|
+
if (c == '\n') { /* any \n ends a line */
|
275
|
+
i++; /* keep the \n; we know there is room for \0 */
|
276
|
+
break;
|
277
|
+
}
|
278
|
+
if (crflag) { /* \r not followed by \n ends line at the \r */
|
279
|
+
ungetc(c, file);
|
280
|
+
break; /* and overwrite c in buf with \0 */
|
281
|
+
}
|
282
|
+
crflag = (c == '\r');
|
283
|
+
}
|
284
|
+
|
285
|
+
buf[i] = '\0';
|
286
|
+
return i;
|
287
|
+
}
|
288
|
+
|
289
|
+
static int32
|
290
|
+
GetChar(JSTokenStream *ts)
|
291
|
+
{
|
292
|
+
int32 c;
|
293
|
+
ptrdiff_t i, j, len, olen;
|
294
|
+
JSBool crflag;
|
295
|
+
char cbuf[JS_LINE_LIMIT];
|
296
|
+
jschar *ubuf, *nl;
|
297
|
+
|
298
|
+
if (ts->ungetpos != 0) {
|
299
|
+
c = ts->ungetbuf[--ts->ungetpos];
|
300
|
+
} else {
|
301
|
+
do {
|
302
|
+
if (ts->linebuf.ptr == ts->linebuf.limit) {
|
303
|
+
len = PTRDIFF(ts->userbuf.limit, ts->userbuf.ptr, jschar);
|
304
|
+
if (len <= 0) {
|
305
|
+
if (!ts->file) {
|
306
|
+
ts->flags |= TSF_EOF;
|
307
|
+
return EOF;
|
308
|
+
}
|
309
|
+
|
310
|
+
/* Fill ts->userbuf so that \r and \r\n convert to \n. */
|
311
|
+
crflag = (ts->flags & TSF_CRFLAG) != 0;
|
312
|
+
len = js_fgets(cbuf, JS_LINE_LIMIT - crflag, ts->file);
|
313
|
+
if (len <= 0) {
|
314
|
+
ts->flags |= TSF_EOF;
|
315
|
+
return EOF;
|
316
|
+
}
|
317
|
+
olen = len;
|
318
|
+
ubuf = ts->userbuf.base;
|
319
|
+
i = 0;
|
320
|
+
if (crflag) {
|
321
|
+
ts->flags &= ~TSF_CRFLAG;
|
322
|
+
if (cbuf[0] != '\n') {
|
323
|
+
ubuf[i++] = '\n';
|
324
|
+
len++;
|
325
|
+
ts->linepos--;
|
326
|
+
}
|
327
|
+
}
|
328
|
+
for (j = 0; i < len; i++, j++)
|
329
|
+
ubuf[i] = (jschar) (unsigned char) cbuf[j];
|
330
|
+
ts->userbuf.limit = ubuf + len;
|
331
|
+
ts->userbuf.ptr = ubuf;
|
332
|
+
}
|
333
|
+
if (ts->listener) {
|
334
|
+
ts->listener(ts->filename, ts->lineno, ts->userbuf.ptr, len,
|
335
|
+
&ts->listenerTSData, ts->listenerData);
|
336
|
+
}
|
337
|
+
|
338
|
+
nl = ts->saveEOL;
|
339
|
+
if (!nl) {
|
340
|
+
/*
|
341
|
+
* Any one of \n, \r, or \r\n ends a line (the longest
|
342
|
+
* match wins). Also allow the Unicode line and paragraph
|
343
|
+
* separators.
|
344
|
+
*/
|
345
|
+
for (nl = ts->userbuf.ptr; nl < ts->userbuf.limit; nl++) {
|
346
|
+
/*
|
347
|
+
* Try to prevent value-testing on most characters by
|
348
|
+
* filtering out characters that aren't 000x or 202x.
|
349
|
+
*/
|
350
|
+
if ((*nl & 0xDFD0) == 0) {
|
351
|
+
if (*nl == '\n')
|
352
|
+
break;
|
353
|
+
if (*nl == '\r') {
|
354
|
+
if (nl + 1 < ts->userbuf.limit && nl[1] == '\n')
|
355
|
+
nl++;
|
356
|
+
break;
|
357
|
+
}
|
358
|
+
if (*nl == LINE_SEPARATOR || *nl == PARA_SEPARATOR)
|
359
|
+
break;
|
360
|
+
}
|
361
|
+
}
|
362
|
+
}
|
363
|
+
|
364
|
+
/*
|
365
|
+
* If there was a line terminator, copy thru it into linebuf.
|
366
|
+
* Else copy JS_LINE_LIMIT-1 bytes into linebuf.
|
367
|
+
*/
|
368
|
+
if (nl < ts->userbuf.limit)
|
369
|
+
len = PTRDIFF(nl, ts->userbuf.ptr, jschar) + 1;
|
370
|
+
if (len >= JS_LINE_LIMIT) {
|
371
|
+
len = JS_LINE_LIMIT - 1;
|
372
|
+
ts->saveEOL = nl;
|
373
|
+
} else {
|
374
|
+
ts->saveEOL = NULL;
|
375
|
+
}
|
376
|
+
js_strncpy(ts->linebuf.base, ts->userbuf.ptr, len);
|
377
|
+
ts->userbuf.ptr += len;
|
378
|
+
olen = len;
|
379
|
+
|
380
|
+
/*
|
381
|
+
* Make sure linebuf contains \n for EOL (don't do this in
|
382
|
+
* userbuf because the user's string might be readonly).
|
383
|
+
*/
|
384
|
+
if (nl < ts->userbuf.limit) {
|
385
|
+
if (*nl == '\r') {
|
386
|
+
if (ts->linebuf.base[len-1] == '\r') {
|
387
|
+
/*
|
388
|
+
* Does the line segment end in \r? We must check
|
389
|
+
* for a \n at the front of the next segment before
|
390
|
+
* storing a \n into linebuf. This case matters
|
391
|
+
* only when we're reading from a file.
|
392
|
+
*/
|
393
|
+
if (nl + 1 == ts->userbuf.limit && ts->file) {
|
394
|
+
len--;
|
395
|
+
ts->flags |= TSF_CRFLAG; /* clear NLFLAG? */
|
396
|
+
if (len == 0) {
|
397
|
+
/*
|
398
|
+
* This can happen when a segment ends in
|
399
|
+
* \r\r. Start over. ptr == limit in this
|
400
|
+
* case, so we'll fall into buffer-filling
|
401
|
+
* code.
|
402
|
+
*/
|
403
|
+
return GetChar(ts);
|
404
|
+
}
|
405
|
+
} else {
|
406
|
+
ts->linebuf.base[len-1] = '\n';
|
407
|
+
}
|
408
|
+
}
|
409
|
+
} else if (*nl == '\n') {
|
410
|
+
if (nl > ts->userbuf.base &&
|
411
|
+
nl[-1] == '\r' &&
|
412
|
+
ts->linebuf.base[len-2] == '\r') {
|
413
|
+
len--;
|
414
|
+
JS_ASSERT(ts->linebuf.base[len] == '\n');
|
415
|
+
ts->linebuf.base[len-1] = '\n';
|
416
|
+
}
|
417
|
+
} else if (*nl == LINE_SEPARATOR || *nl == PARA_SEPARATOR) {
|
418
|
+
ts->linebuf.base[len-1] = '\n';
|
419
|
+
}
|
420
|
+
}
|
421
|
+
|
422
|
+
/* Reset linebuf based on adjusted segment length. */
|
423
|
+
ts->linebuf.limit = ts->linebuf.base + len;
|
424
|
+
ts->linebuf.ptr = ts->linebuf.base;
|
425
|
+
|
426
|
+
/* Update position of linebuf within physical userbuf line. */
|
427
|
+
if (!(ts->flags & TSF_NLFLAG))
|
428
|
+
ts->linepos += ts->linelen;
|
429
|
+
else
|
430
|
+
ts->linepos = 0;
|
431
|
+
if (ts->linebuf.limit[-1] == '\n')
|
432
|
+
ts->flags |= TSF_NLFLAG;
|
433
|
+
else
|
434
|
+
ts->flags &= ~TSF_NLFLAG;
|
435
|
+
|
436
|
+
/* Update linelen from original segment length. */
|
437
|
+
ts->linelen = olen;
|
438
|
+
}
|
439
|
+
c = *ts->linebuf.ptr++;
|
440
|
+
/*
|
441
|
+
* In the hopes of being liberal in what we accept, we toss out little-
|
442
|
+
* and big-endian byte order markers here, see bug 368516.
|
443
|
+
*/
|
444
|
+
} while (c == 0xfffe || c == 0xfeff);
|
445
|
+
}
|
446
|
+
if (c == '\n')
|
447
|
+
ts->lineno++;
|
448
|
+
return c;
|
449
|
+
}
|
450
|
+
|
451
|
+
static void
|
452
|
+
UngetChar(JSTokenStream *ts, int32 c)
|
453
|
+
{
|
454
|
+
if (c == EOF)
|
455
|
+
return;
|
456
|
+
JS_ASSERT(ts->ungetpos < JS_ARRAY_LENGTH(ts->ungetbuf));
|
457
|
+
if (c == '\n')
|
458
|
+
ts->lineno--;
|
459
|
+
ts->ungetbuf[ts->ungetpos++] = (jschar)c;
|
460
|
+
}
|
461
|
+
|
462
|
+
static int32
|
463
|
+
PeekChar(JSTokenStream *ts)
|
464
|
+
{
|
465
|
+
int32 c;
|
466
|
+
|
467
|
+
c = GetChar(ts);
|
468
|
+
UngetChar(ts, c);
|
469
|
+
return c;
|
470
|
+
}
|
471
|
+
|
472
|
+
/*
|
473
|
+
* Peek n chars ahead into ts. Return true if n chars were read, false if
|
474
|
+
* there weren't enough characters in the input stream. This function cannot
|
475
|
+
* be used to peek into or past a newline.
|
476
|
+
*/
|
477
|
+
static JSBool
|
478
|
+
PeekChars(JSTokenStream *ts, intN n, jschar *cp)
|
479
|
+
{
|
480
|
+
intN i, j;
|
481
|
+
int32 c;
|
482
|
+
|
483
|
+
for (i = 0; i < n; i++) {
|
484
|
+
c = GetChar(ts);
|
485
|
+
if (c == EOF)
|
486
|
+
break;
|
487
|
+
if (c == '\n') {
|
488
|
+
UngetChar(ts, c);
|
489
|
+
break;
|
490
|
+
}
|
491
|
+
cp[i] = (jschar)c;
|
492
|
+
}
|
493
|
+
for (j = i - 1; j >= 0; j--)
|
494
|
+
UngetChar(ts, cp[j]);
|
495
|
+
return i == n;
|
496
|
+
}
|
497
|
+
|
498
|
+
static void
|
499
|
+
SkipChars(JSTokenStream *ts, intN n)
|
500
|
+
{
|
501
|
+
while (--n >= 0)
|
502
|
+
GetChar(ts);
|
503
|
+
}
|
504
|
+
|
505
|
+
static JSBool
|
506
|
+
MatchChar(JSTokenStream *ts, int32 expect)
|
507
|
+
{
|
508
|
+
int32 c;
|
509
|
+
|
510
|
+
c = GetChar(ts);
|
511
|
+
if (c == expect)
|
512
|
+
return JS_TRUE;
|
513
|
+
UngetChar(ts, c);
|
514
|
+
return JS_FALSE;
|
515
|
+
}
|
516
|
+
|
517
|
+
JSBool
|
518
|
+
js_ReportCompileErrorNumber(JSContext *cx, JSTokenStream *ts, JSParseNode *pn,
|
519
|
+
uintN flags, uintN errorNumber, ...)
|
520
|
+
{
|
521
|
+
JSErrorReport report;
|
522
|
+
char *message;
|
523
|
+
size_t linelength;
|
524
|
+
jschar *linechars;
|
525
|
+
char *linebytes;
|
526
|
+
va_list ap;
|
527
|
+
JSBool warning, ok;
|
528
|
+
JSTokenPos *tp;
|
529
|
+
uintN index, i;
|
530
|
+
JSErrorReporter onError;
|
531
|
+
|
532
|
+
JS_ASSERT(ts->linebuf.limit < ts->linebuf.base + JS_LINE_LIMIT);
|
533
|
+
|
534
|
+
if ((flags & JSREPORT_STRICT) && !JS_HAS_STRICT_OPTION(cx))
|
535
|
+
return JS_TRUE;
|
536
|
+
|
537
|
+
memset(&report, 0, sizeof report);
|
538
|
+
report.flags = flags;
|
539
|
+
report.errorNumber = errorNumber;
|
540
|
+
message = NULL;
|
541
|
+
linechars = NULL;
|
542
|
+
linebytes = NULL;
|
543
|
+
|
544
|
+
/* From this point the control must flow through the label out.*/
|
545
|
+
va_start(ap, errorNumber);
|
546
|
+
ok = js_ExpandErrorArguments(cx, js_GetErrorMessage, NULL,
|
547
|
+
errorNumber, &message, &report, &warning,
|
548
|
+
!(flags & JSREPORT_UC), ap);
|
549
|
+
va_end(ap);
|
550
|
+
if (!ok) {
|
551
|
+
warning = JS_FALSE;
|
552
|
+
goto out;
|
553
|
+
}
|
554
|
+
|
555
|
+
report.filename = ts->filename;
|
556
|
+
|
557
|
+
if (pn) {
|
558
|
+
report.lineno = pn->pn_pos.begin.lineno;
|
559
|
+
if (report.lineno != ts->lineno)
|
560
|
+
goto report;
|
561
|
+
tp = &pn->pn_pos;
|
562
|
+
} else {
|
563
|
+
/* Point to the current token, not the next one to get. */
|
564
|
+
tp = &ts->tokens[ts->cursor].pos;
|
565
|
+
}
|
566
|
+
report.lineno = ts->lineno;
|
567
|
+
linelength = PTRDIFF(ts->linebuf.limit, ts->linebuf.base, jschar);
|
568
|
+
linechars = (jschar *)JS_malloc(cx, (linelength + 1) * sizeof(jschar));
|
569
|
+
if (!linechars) {
|
570
|
+
warning = JS_FALSE;
|
571
|
+
goto out;
|
572
|
+
}
|
573
|
+
memcpy(linechars, ts->linebuf.base, linelength * sizeof(jschar));
|
574
|
+
linechars[linelength] = 0;
|
575
|
+
linebytes = js_DeflateString(cx, linechars, linelength);
|
576
|
+
if (!linebytes) {
|
577
|
+
warning = JS_FALSE;
|
578
|
+
goto out;
|
579
|
+
}
|
580
|
+
report.linebuf = linebytes;
|
581
|
+
|
582
|
+
/*
|
583
|
+
* FIXME: What should instead happen here is that we should
|
584
|
+
* find error-tokens in userbuf, if !ts->file. That will
|
585
|
+
* allow us to deliver a more helpful error message, which
|
586
|
+
* includes all or part of the bad string or bad token. The
|
587
|
+
* code here yields something that looks truncated.
|
588
|
+
* See https://bugzilla.mozilla.org/show_bug.cgi?id=352970
|
589
|
+
*/
|
590
|
+
index = 0;
|
591
|
+
if (tp->begin.lineno == tp->end.lineno) {
|
592
|
+
if (tp->begin.index < ts->linepos)
|
593
|
+
goto report;
|
594
|
+
|
595
|
+
index = tp->begin.index - ts->linepos;
|
596
|
+
}
|
597
|
+
|
598
|
+
report.tokenptr = report.linebuf + index;
|
599
|
+
report.uclinebuf = linechars;
|
600
|
+
report.uctokenptr = report.uclinebuf + index;
|
601
|
+
|
602
|
+
/*
|
603
|
+
* If there's a runtime exception type associated with this error
|
604
|
+
* number, set that as the pending exception. For errors occuring at
|
605
|
+
* compile time, this is very likely to be a JSEXN_SYNTAXERR.
|
606
|
+
*
|
607
|
+
* If an exception is thrown but not caught, the JSREPORT_EXCEPTION
|
608
|
+
* flag will be set in report.flags. Proper behavior for an error
|
609
|
+
* reporter is to ignore a report with this flag for all but top-level
|
610
|
+
* compilation errors. The exception will remain pending, and so long
|
611
|
+
* as the non-top-level "load", "eval", or "compile" native function
|
612
|
+
* returns false, the top-level reporter will eventually receive the
|
613
|
+
* uncaught exception report.
|
614
|
+
*
|
615
|
+
* XXX it'd probably be best if there was only one call to this
|
616
|
+
* function, but there seem to be two error reporter call points.
|
617
|
+
*/
|
618
|
+
report:
|
619
|
+
onError = cx->errorReporter;
|
620
|
+
|
621
|
+
/*
|
622
|
+
* Try to raise an exception only if there isn't one already set --
|
623
|
+
* otherwise the exception will describe the last compile-time error,
|
624
|
+
* which is likely spurious.
|
625
|
+
*/
|
626
|
+
if (!(ts->flags & TSF_ERROR)) {
|
627
|
+
if (js_ErrorToException(cx, message, &report))
|
628
|
+
onError = NULL;
|
629
|
+
}
|
630
|
+
|
631
|
+
/*
|
632
|
+
* Suppress any compile-time errors that don't occur at the top level.
|
633
|
+
* This may still fail, as interplevel may be zero in contexts where we
|
634
|
+
* don't really want to call the error reporter, as when js is called
|
635
|
+
* by other code which could catch the error.
|
636
|
+
*/
|
637
|
+
if (cx->interpLevel != 0 && !JSREPORT_IS_WARNING(flags))
|
638
|
+
onError = NULL;
|
639
|
+
|
640
|
+
if (onError) {
|
641
|
+
JSDebugErrorHook hook = cx->debugHooks->debugErrorHook;
|
642
|
+
|
643
|
+
/*
|
644
|
+
* If debugErrorHook is present then we give it a chance to veto
|
645
|
+
* sending the error on to the regular error reporter.
|
646
|
+
*/
|
647
|
+
if (hook && !hook(cx, message, &report,
|
648
|
+
cx->debugHooks->debugErrorHookData)) {
|
649
|
+
onError = NULL;
|
650
|
+
}
|
651
|
+
}
|
652
|
+
if (onError)
|
653
|
+
(*onError)(cx, message, &report);
|
654
|
+
|
655
|
+
out:
|
656
|
+
if (linebytes)
|
657
|
+
JS_free(cx, linebytes);
|
658
|
+
if (linechars)
|
659
|
+
JS_free(cx, linechars);
|
660
|
+
if (message)
|
661
|
+
JS_free(cx, message);
|
662
|
+
if (report.ucmessage)
|
663
|
+
JS_free(cx, (void *)report.ucmessage);
|
664
|
+
|
665
|
+
if (report.messageArgs) {
|
666
|
+
if (!(flags & JSREPORT_UC)) {
|
667
|
+
i = 0;
|
668
|
+
while (report.messageArgs[i])
|
669
|
+
JS_free(cx, (void *)report.messageArgs[i++]);
|
670
|
+
}
|
671
|
+
JS_free(cx, (void *)report.messageArgs);
|
672
|
+
}
|
673
|
+
|
674
|
+
if (!JSREPORT_IS_WARNING(flags)) {
|
675
|
+
/* Set the error flag to suppress spurious reports. */
|
676
|
+
ts->flags |= TSF_ERROR;
|
677
|
+
}
|
678
|
+
|
679
|
+
return warning;
|
680
|
+
}
|
681
|
+
|
682
|
+
static JSBool
|
683
|
+
GrowStringBuffer(JSStringBuffer *sb, size_t newlength)
|
684
|
+
{
|
685
|
+
ptrdiff_t offset;
|
686
|
+
jschar *bp;
|
687
|
+
|
688
|
+
offset = PTRDIFF(sb->ptr, sb->base, jschar);
|
689
|
+
JS_ASSERT(offset >= 0);
|
690
|
+
newlength += offset + 1;
|
691
|
+
if ((size_t)offset < newlength && newlength < ~(size_t)0 / sizeof(jschar))
|
692
|
+
bp = (jschar *) realloc(sb->base, newlength * sizeof(jschar));
|
693
|
+
else
|
694
|
+
bp = NULL;
|
695
|
+
if (!bp) {
|
696
|
+
free(sb->base);
|
697
|
+
sb->base = STRING_BUFFER_ERROR_BASE;
|
698
|
+
return JS_FALSE;
|
699
|
+
}
|
700
|
+
sb->base = bp;
|
701
|
+
sb->ptr = bp + offset;
|
702
|
+
sb->limit = bp + newlength - 1;
|
703
|
+
return JS_TRUE;
|
704
|
+
}
|
705
|
+
|
706
|
+
static void
|
707
|
+
FreeStringBuffer(JSStringBuffer *sb)
|
708
|
+
{
|
709
|
+
JS_ASSERT(STRING_BUFFER_OK(sb));
|
710
|
+
if (sb->base)
|
711
|
+
free(sb->base);
|
712
|
+
}
|
713
|
+
|
714
|
+
void
|
715
|
+
js_InitStringBuffer(JSStringBuffer *sb)
|
716
|
+
{
|
717
|
+
sb->base = sb->limit = sb->ptr = NULL;
|
718
|
+
sb->data = NULL;
|
719
|
+
sb->grow = GrowStringBuffer;
|
720
|
+
sb->free = FreeStringBuffer;
|
721
|
+
}
|
722
|
+
|
723
|
+
void
|
724
|
+
js_FinishStringBuffer(JSStringBuffer *sb)
|
725
|
+
{
|
726
|
+
sb->free(sb);
|
727
|
+
}
|
728
|
+
|
729
|
+
#define ENSURE_STRING_BUFFER(sb,n) \
|
730
|
+
((sb)->ptr + (n) <= (sb)->limit || sb->grow(sb, n))
|
731
|
+
|
732
|
+
static void
|
733
|
+
FastAppendChar(JSStringBuffer *sb, jschar c)
|
734
|
+
{
|
735
|
+
if (!STRING_BUFFER_OK(sb))
|
736
|
+
return;
|
737
|
+
if (!ENSURE_STRING_BUFFER(sb, 1))
|
738
|
+
return;
|
739
|
+
*sb->ptr++ = c;
|
740
|
+
}
|
741
|
+
|
742
|
+
void
|
743
|
+
js_AppendChar(JSStringBuffer *sb, jschar c)
|
744
|
+
{
|
745
|
+
jschar *bp;
|
746
|
+
|
747
|
+
if (!STRING_BUFFER_OK(sb))
|
748
|
+
return;
|
749
|
+
if (!ENSURE_STRING_BUFFER(sb, 1))
|
750
|
+
return;
|
751
|
+
bp = sb->ptr;
|
752
|
+
*bp++ = c;
|
753
|
+
*bp = 0;
|
754
|
+
sb->ptr = bp;
|
755
|
+
}
|
756
|
+
|
757
|
+
#if JS_HAS_XML_SUPPORT
|
758
|
+
|
759
|
+
void
|
760
|
+
js_RepeatChar(JSStringBuffer *sb, jschar c, uintN count)
|
761
|
+
{
|
762
|
+
jschar *bp;
|
763
|
+
|
764
|
+
if (!STRING_BUFFER_OK(sb) || count == 0)
|
765
|
+
return;
|
766
|
+
if (!ENSURE_STRING_BUFFER(sb, count))
|
767
|
+
return;
|
768
|
+
for (bp = sb->ptr; count; --count)
|
769
|
+
*bp++ = c;
|
770
|
+
*bp = 0;
|
771
|
+
sb->ptr = bp;
|
772
|
+
}
|
773
|
+
|
774
|
+
void
|
775
|
+
js_AppendCString(JSStringBuffer *sb, const char *asciiz)
|
776
|
+
{
|
777
|
+
size_t length;
|
778
|
+
jschar *bp;
|
779
|
+
|
780
|
+
if (!STRING_BUFFER_OK(sb) || *asciiz == '\0')
|
781
|
+
return;
|
782
|
+
length = strlen(asciiz);
|
783
|
+
if (!ENSURE_STRING_BUFFER(sb, length))
|
784
|
+
return;
|
785
|
+
for (bp = sb->ptr; length; --length)
|
786
|
+
*bp++ = (jschar) *asciiz++;
|
787
|
+
*bp = 0;
|
788
|
+
sb->ptr = bp;
|
789
|
+
}
|
790
|
+
|
791
|
+
void
|
792
|
+
js_AppendJSString(JSStringBuffer *sb, JSString *str)
|
793
|
+
{
|
794
|
+
size_t length;
|
795
|
+
jschar *bp;
|
796
|
+
|
797
|
+
if (!STRING_BUFFER_OK(sb))
|
798
|
+
return;
|
799
|
+
length = JSSTRING_LENGTH(str);
|
800
|
+
if (length == 0 || !ENSURE_STRING_BUFFER(sb, length))
|
801
|
+
return;
|
802
|
+
bp = sb->ptr;
|
803
|
+
js_strncpy(bp, JSSTRING_CHARS(str), length);
|
804
|
+
bp += length;
|
805
|
+
*bp = 0;
|
806
|
+
sb->ptr = bp;
|
807
|
+
}
|
808
|
+
|
809
|
+
static JSBool
|
810
|
+
GetXMLEntity(JSContext *cx, JSTokenStream *ts)
|
811
|
+
{
|
812
|
+
ptrdiff_t offset, length, i;
|
813
|
+
int32 c, d;
|
814
|
+
JSBool ispair;
|
815
|
+
jschar *bp, digit;
|
816
|
+
char *bytes;
|
817
|
+
JSErrNum msg;
|
818
|
+
|
819
|
+
/* Put the entity, including the '&' already scanned, in ts->tokenbuf. */
|
820
|
+
offset = PTRDIFF(ts->tokenbuf.ptr, ts->tokenbuf.base, jschar);
|
821
|
+
FastAppendChar(&ts->tokenbuf, '&');
|
822
|
+
while ((c = GetChar(ts)) != ';') {
|
823
|
+
if (c == EOF || c == '\n') {
|
824
|
+
js_ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR,
|
825
|
+
JSMSG_END_OF_XML_ENTITY);
|
826
|
+
return JS_FALSE;
|
827
|
+
}
|
828
|
+
FastAppendChar(&ts->tokenbuf, (jschar) c);
|
829
|
+
}
|
830
|
+
|
831
|
+
/* Let length be the number of jschars after the '&', including the ';'. */
|
832
|
+
length = PTRDIFF(ts->tokenbuf.ptr, ts->tokenbuf.base, jschar) - offset;
|
833
|
+
bp = ts->tokenbuf.base + offset;
|
834
|
+
c = d = 0;
|
835
|
+
ispair = JS_FALSE;
|
836
|
+
if (length > 2 && bp[1] == '#') {
|
837
|
+
/* Match a well-formed XML Character Reference. */
|
838
|
+
i = 2;
|
839
|
+
if (length > 3 && JS_TOLOWER(bp[i]) == 'x') {
|
840
|
+
if (length > 9) /* at most 6 hex digits allowed */
|
841
|
+
goto badncr;
|
842
|
+
while (++i < length) {
|
843
|
+
digit = bp[i];
|
844
|
+
if (!JS7_ISHEX(digit))
|
845
|
+
goto badncr;
|
846
|
+
c = (c << 4) + JS7_UNHEX(digit);
|
847
|
+
}
|
848
|
+
} else {
|
849
|
+
while (i < length) {
|
850
|
+
digit = bp[i++];
|
851
|
+
if (!JS7_ISDEC(digit))
|
852
|
+
goto badncr;
|
853
|
+
c = (c * 10) + JS7_UNDEC(digit);
|
854
|
+
if (c < 0)
|
855
|
+
goto badncr;
|
856
|
+
}
|
857
|
+
}
|
858
|
+
|
859
|
+
if (0x10000 <= c && c <= 0x10FFFF) {
|
860
|
+
/* Form a surrogate pair (c, d) -- c is the high surrogate. */
|
861
|
+
d = 0xDC00 + (c & 0x3FF);
|
862
|
+
c = 0xD7C0 + (c >> 10);
|
863
|
+
ispair = JS_TRUE;
|
864
|
+
} else {
|
865
|
+
/* Enforce the http://www.w3.org/TR/REC-xml/#wf-Legalchar WFC. */
|
866
|
+
if (c != 0x9 && c != 0xA && c != 0xD &&
|
867
|
+
!(0x20 <= c && c <= 0xD7FF) &&
|
868
|
+
!(0xE000 <= c && c <= 0xFFFD)) {
|
869
|
+
goto badncr;
|
870
|
+
}
|
871
|
+
}
|
872
|
+
} else {
|
873
|
+
/* Try to match one of the five XML 1.0 predefined entities. */
|
874
|
+
switch (length) {
|
875
|
+
case 3:
|
876
|
+
if (bp[2] == 't') {
|
877
|
+
if (bp[1] == 'l')
|
878
|
+
c = '<';
|
879
|
+
else if (bp[1] == 'g')
|
880
|
+
c = '>';
|
881
|
+
}
|
882
|
+
break;
|
883
|
+
case 4:
|
884
|
+
if (bp[1] == 'a' && bp[2] == 'm' && bp[3] == 'p')
|
885
|
+
c = '&';
|
886
|
+
break;
|
887
|
+
case 5:
|
888
|
+
if (bp[3] == 'o') {
|
889
|
+
if (bp[1] == 'a' && bp[2] == 'p' && bp[4] == 's')
|
890
|
+
c = '\'';
|
891
|
+
else if (bp[1] == 'q' && bp[2] == 'u' && bp[4] == 't')
|
892
|
+
c = '"';
|
893
|
+
}
|
894
|
+
break;
|
895
|
+
}
|
896
|
+
if (c == 0) {
|
897
|
+
msg = JSMSG_UNKNOWN_XML_ENTITY;
|
898
|
+
goto bad;
|
899
|
+
}
|
900
|
+
}
|
901
|
+
|
902
|
+
/* If we matched, retract ts->tokenbuf and store the entity's value. */
|
903
|
+
*bp++ = (jschar) c;
|
904
|
+
if (ispair)
|
905
|
+
*bp++ = (jschar) d;
|
906
|
+
*bp = 0;
|
907
|
+
ts->tokenbuf.ptr = bp;
|
908
|
+
return JS_TRUE;
|
909
|
+
|
910
|
+
badncr:
|
911
|
+
msg = JSMSG_BAD_XML_NCR;
|
912
|
+
bad:
|
913
|
+
/* No match: throw a TypeError per ECMA-357 10.3.2.1 step 8(a). */
|
914
|
+
bytes = js_DeflateString(cx, bp + 1,
|
915
|
+
PTRDIFF(ts->tokenbuf.ptr, bp, jschar) - 1);
|
916
|
+
if (bytes) {
|
917
|
+
js_ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR,
|
918
|
+
msg, bytes);
|
919
|
+
JS_free(cx, bytes);
|
920
|
+
}
|
921
|
+
return JS_FALSE;
|
922
|
+
}
|
923
|
+
|
924
|
+
#endif /* JS_HAS_XML_SUPPORT */
|
925
|
+
|
926
|
+
JSTokenType
|
927
|
+
js_PeekToken(JSContext *cx, JSTokenStream *ts)
|
928
|
+
{
|
929
|
+
JSTokenType tt;
|
930
|
+
|
931
|
+
if (ts->lookahead != 0) {
|
932
|
+
tt = ts->tokens[(ts->cursor + ts->lookahead) & NTOKENS_MASK].type;
|
933
|
+
} else {
|
934
|
+
tt = js_GetToken(cx, ts);
|
935
|
+
js_UngetToken(ts);
|
936
|
+
}
|
937
|
+
return tt;
|
938
|
+
}
|
939
|
+
|
940
|
+
JSTokenType
|
941
|
+
js_PeekTokenSameLine(JSContext *cx, JSTokenStream *ts)
|
942
|
+
{
|
943
|
+
JSTokenType tt;
|
944
|
+
|
945
|
+
if (!ON_CURRENT_LINE(ts, CURRENT_TOKEN(ts).pos))
|
946
|
+
return TOK_EOL;
|
947
|
+
ts->flags |= TSF_NEWLINES;
|
948
|
+
tt = js_PeekToken(cx, ts);
|
949
|
+
ts->flags &= ~TSF_NEWLINES;
|
950
|
+
return tt;
|
951
|
+
}
|
952
|
+
|
953
|
+
/*
|
954
|
+
* We have encountered a '\': check for a Unicode escape sequence after it,
|
955
|
+
* returning the character code value if we found a Unicode escape sequence.
|
956
|
+
* Otherwise, non-destructively return the original '\'.
|
957
|
+
*/
|
958
|
+
static int32
|
959
|
+
GetUnicodeEscape(JSTokenStream *ts)
|
960
|
+
{
|
961
|
+
jschar cp[5];
|
962
|
+
int32 c;
|
963
|
+
|
964
|
+
if (PeekChars(ts, 5, cp) && cp[0] == 'u' &&
|
965
|
+
JS7_ISHEX(cp[1]) && JS7_ISHEX(cp[2]) &&
|
966
|
+
JS7_ISHEX(cp[3]) && JS7_ISHEX(cp[4]))
|
967
|
+
{
|
968
|
+
c = (((((JS7_UNHEX(cp[1]) << 4)
|
969
|
+
+ JS7_UNHEX(cp[2])) << 4)
|
970
|
+
+ JS7_UNHEX(cp[3])) << 4)
|
971
|
+
+ JS7_UNHEX(cp[4]);
|
972
|
+
SkipChars(ts, 5);
|
973
|
+
return c;
|
974
|
+
}
|
975
|
+
return '\\';
|
976
|
+
}
|
977
|
+
|
978
|
+
static JSToken *
|
979
|
+
NewToken(JSTokenStream *ts, ptrdiff_t adjust)
|
980
|
+
{
|
981
|
+
JSToken *tp;
|
982
|
+
|
983
|
+
ts->cursor = (ts->cursor + 1) & NTOKENS_MASK;
|
984
|
+
tp = &CURRENT_TOKEN(ts);
|
985
|
+
tp->ptr = ts->linebuf.ptr + adjust;
|
986
|
+
tp->pos.begin.index = ts->linepos +
|
987
|
+
PTRDIFF(tp->ptr, ts->linebuf.base, jschar) -
|
988
|
+
ts->ungetpos;
|
989
|
+
tp->pos.begin.lineno = tp->pos.end.lineno = (uint16)ts->lineno;
|
990
|
+
return tp;
|
991
|
+
}
|
992
|
+
|
993
|
+
JSTokenType
|
994
|
+
js_GetToken(JSContext *cx, JSTokenStream *ts)
|
995
|
+
{
|
996
|
+
JSTokenType tt;
|
997
|
+
int32 c, qc;
|
998
|
+
JSToken *tp;
|
999
|
+
JSAtom *atom;
|
1000
|
+
JSBool hadUnicodeEscape;
|
1001
|
+
const struct keyword *kw;
|
1002
|
+
#if JS_HAS_XML_SUPPORT
|
1003
|
+
JSBool inTarget;
|
1004
|
+
size_t targetLength;
|
1005
|
+
ptrdiff_t contentIndex;
|
1006
|
+
#endif
|
1007
|
+
|
1008
|
+
#define INIT_TOKENBUF() (ts->tokenbuf.ptr = ts->tokenbuf.base)
|
1009
|
+
#define TOKENBUF_LENGTH() PTRDIFF(ts->tokenbuf.ptr, ts->tokenbuf.base, jschar)
|
1010
|
+
#define TOKENBUF_OK() STRING_BUFFER_OK(&ts->tokenbuf)
|
1011
|
+
#define TOKENBUF_TO_ATOM() (TOKENBUF_OK() \
|
1012
|
+
? js_AtomizeChars(cx, \
|
1013
|
+
TOKENBUF_BASE(), \
|
1014
|
+
TOKENBUF_LENGTH(), \
|
1015
|
+
0) \
|
1016
|
+
: NULL)
|
1017
|
+
#define ADD_TO_TOKENBUF(c) FastAppendChar(&ts->tokenbuf, (jschar) (c))
|
1018
|
+
|
1019
|
+
/* The following 4 macros should only be used when TOKENBUF_OK() is true. */
|
1020
|
+
#define TOKENBUF_BASE() (ts->tokenbuf.base)
|
1021
|
+
#define TOKENBUF_END() (ts->tokenbuf.ptr)
|
1022
|
+
#define TOKENBUF_CHAR(i) (ts->tokenbuf.base[i])
|
1023
|
+
#define TRIM_TOKENBUF(i) (ts->tokenbuf.ptr = ts->tokenbuf.base + i)
|
1024
|
+
#define NUL_TERM_TOKENBUF() (*ts->tokenbuf.ptr = 0)
|
1025
|
+
|
1026
|
+
/* Check for a pushed-back token resulting from mismatching lookahead. */
|
1027
|
+
while (ts->lookahead != 0) {
|
1028
|
+
JS_ASSERT(!(ts->flags & TSF_XMLTEXTMODE));
|
1029
|
+
ts->lookahead--;
|
1030
|
+
ts->cursor = (ts->cursor + 1) & NTOKENS_MASK;
|
1031
|
+
tt = CURRENT_TOKEN(ts).type;
|
1032
|
+
if (tt != TOK_EOL || (ts->flags & TSF_NEWLINES))
|
1033
|
+
return tt;
|
1034
|
+
}
|
1035
|
+
|
1036
|
+
/* If there was a fatal error, keep returning TOK_ERROR. */
|
1037
|
+
if (ts->flags & TSF_ERROR)
|
1038
|
+
return TOK_ERROR;
|
1039
|
+
|
1040
|
+
#if JS_HAS_XML_SUPPORT
|
1041
|
+
if (ts->flags & TSF_XMLTEXTMODE) {
|
1042
|
+
tt = TOK_XMLSPACE; /* veto if non-space, return TOK_XMLTEXT */
|
1043
|
+
tp = NewToken(ts, 0);
|
1044
|
+
INIT_TOKENBUF();
|
1045
|
+
qc = (ts->flags & TSF_XMLONLYMODE) ? '<' : '{';
|
1046
|
+
|
1047
|
+
while ((c = GetChar(ts)) != qc && c != '<' && c != EOF) {
|
1048
|
+
if (c == '&' && qc == '<') {
|
1049
|
+
if (!GetXMLEntity(cx, ts))
|
1050
|
+
goto error;
|
1051
|
+
tt = TOK_XMLTEXT;
|
1052
|
+
continue;
|
1053
|
+
}
|
1054
|
+
|
1055
|
+
if (!JS_ISXMLSPACE(c))
|
1056
|
+
tt = TOK_XMLTEXT;
|
1057
|
+
ADD_TO_TOKENBUF(c);
|
1058
|
+
}
|
1059
|
+
UngetChar(ts, c);
|
1060
|
+
|
1061
|
+
if (TOKENBUF_LENGTH() == 0) {
|
1062
|
+
atom = NULL;
|
1063
|
+
} else {
|
1064
|
+
atom = TOKENBUF_TO_ATOM();
|
1065
|
+
if (!atom)
|
1066
|
+
goto error;
|
1067
|
+
}
|
1068
|
+
tp->pos.end.lineno = (uint16)ts->lineno;
|
1069
|
+
tp->t_op = JSOP_STRING;
|
1070
|
+
tp->t_atom = atom;
|
1071
|
+
goto out;
|
1072
|
+
}
|
1073
|
+
|
1074
|
+
if (ts->flags & TSF_XMLTAGMODE) {
|
1075
|
+
tp = NewToken(ts, 0);
|
1076
|
+
c = GetChar(ts);
|
1077
|
+
if (JS_ISXMLSPACE(c)) {
|
1078
|
+
do {
|
1079
|
+
c = GetChar(ts);
|
1080
|
+
} while (JS_ISXMLSPACE(c));
|
1081
|
+
UngetChar(ts, c);
|
1082
|
+
tt = TOK_XMLSPACE;
|
1083
|
+
goto out;
|
1084
|
+
}
|
1085
|
+
|
1086
|
+
if (c == EOF) {
|
1087
|
+
tt = TOK_EOF;
|
1088
|
+
goto out;
|
1089
|
+
}
|
1090
|
+
|
1091
|
+
INIT_TOKENBUF();
|
1092
|
+
if (JS_ISXMLNSSTART(c)) {
|
1093
|
+
JSBool sawColon = JS_FALSE;
|
1094
|
+
|
1095
|
+
ADD_TO_TOKENBUF(c);
|
1096
|
+
while ((c = GetChar(ts)) != EOF && JS_ISXMLNAME(c)) {
|
1097
|
+
if (c == ':') {
|
1098
|
+
int nextc;
|
1099
|
+
|
1100
|
+
if (sawColon ||
|
1101
|
+
(nextc = PeekChar(ts),
|
1102
|
+
((ts->flags & TSF_XMLONLYMODE) || nextc != '{') &&
|
1103
|
+
!JS_ISXMLNAME(nextc))) {
|
1104
|
+
js_ReportCompileErrorNumber(cx, ts, NULL,
|
1105
|
+
JSREPORT_ERROR,
|
1106
|
+
JSMSG_BAD_XML_QNAME);
|
1107
|
+
goto error;
|
1108
|
+
}
|
1109
|
+
sawColon = JS_TRUE;
|
1110
|
+
}
|
1111
|
+
|
1112
|
+
ADD_TO_TOKENBUF(c);
|
1113
|
+
}
|
1114
|
+
|
1115
|
+
UngetChar(ts, c);
|
1116
|
+
atom = TOKENBUF_TO_ATOM();
|
1117
|
+
if (!atom)
|
1118
|
+
goto error;
|
1119
|
+
tp->t_op = JSOP_STRING;
|
1120
|
+
tp->t_atom = atom;
|
1121
|
+
tt = TOK_XMLNAME;
|
1122
|
+
goto out;
|
1123
|
+
}
|
1124
|
+
|
1125
|
+
switch (c) {
|
1126
|
+
case '{':
|
1127
|
+
if (ts->flags & TSF_XMLONLYMODE)
|
1128
|
+
goto bad_xml_char;
|
1129
|
+
tt = TOK_LC;
|
1130
|
+
goto out;
|
1131
|
+
|
1132
|
+
case '=':
|
1133
|
+
tt = TOK_ASSIGN;
|
1134
|
+
goto out;
|
1135
|
+
|
1136
|
+
case '"':
|
1137
|
+
case '\'':
|
1138
|
+
qc = c;
|
1139
|
+
while ((c = GetChar(ts)) != qc) {
|
1140
|
+
if (c == EOF) {
|
1141
|
+
js_ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR,
|
1142
|
+
JSMSG_UNTERMINATED_STRING);
|
1143
|
+
goto error;
|
1144
|
+
}
|
1145
|
+
|
1146
|
+
/*
|
1147
|
+
* XML attribute values are double-quoted when pretty-printed,
|
1148
|
+
* so escape " if it is expressed directly in a single-quoted
|
1149
|
+
* attribute value.
|
1150
|
+
*/
|
1151
|
+
if (c == '"' && !(ts->flags & TSF_XMLONLYMODE)) {
|
1152
|
+
JS_ASSERT(qc == '\'');
|
1153
|
+
js_AppendCString(&ts->tokenbuf, js_quot_entity_str);
|
1154
|
+
continue;
|
1155
|
+
}
|
1156
|
+
|
1157
|
+
if (c == '&' && (ts->flags & TSF_XMLONLYMODE)) {
|
1158
|
+
if (!GetXMLEntity(cx, ts))
|
1159
|
+
goto error;
|
1160
|
+
continue;
|
1161
|
+
}
|
1162
|
+
|
1163
|
+
ADD_TO_TOKENBUF(c);
|
1164
|
+
}
|
1165
|
+
atom = TOKENBUF_TO_ATOM();
|
1166
|
+
if (!atom)
|
1167
|
+
goto error;
|
1168
|
+
tp->pos.end.lineno = (uint16)ts->lineno;
|
1169
|
+
tp->t_op = JSOP_STRING;
|
1170
|
+
tp->t_atom = atom;
|
1171
|
+
tt = TOK_XMLATTR;
|
1172
|
+
goto out;
|
1173
|
+
|
1174
|
+
case '>':
|
1175
|
+
tt = TOK_XMLTAGC;
|
1176
|
+
goto out;
|
1177
|
+
|
1178
|
+
case '/':
|
1179
|
+
if (MatchChar(ts, '>')) {
|
1180
|
+
tt = TOK_XMLPTAGC;
|
1181
|
+
goto out;
|
1182
|
+
}
|
1183
|
+
/* FALL THROUGH */
|
1184
|
+
|
1185
|
+
bad_xml_char:
|
1186
|
+
default:
|
1187
|
+
js_ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR,
|
1188
|
+
JSMSG_BAD_XML_CHARACTER);
|
1189
|
+
goto error;
|
1190
|
+
}
|
1191
|
+
/* NOTREACHED */
|
1192
|
+
}
|
1193
|
+
#endif /* JS_HAS_XML_SUPPORT */
|
1194
|
+
|
1195
|
+
retry:
|
1196
|
+
do {
|
1197
|
+
c = GetChar(ts);
|
1198
|
+
if (c == '\n') {
|
1199
|
+
ts->flags &= ~TSF_DIRTYLINE;
|
1200
|
+
if (ts->flags & TSF_NEWLINES)
|
1201
|
+
break;
|
1202
|
+
}
|
1203
|
+
} while (JS_ISSPACE(c));
|
1204
|
+
|
1205
|
+
tp = NewToken(ts, -1);
|
1206
|
+
if (c == EOF) {
|
1207
|
+
tt = TOK_EOF;
|
1208
|
+
goto out;
|
1209
|
+
}
|
1210
|
+
|
1211
|
+
hadUnicodeEscape = JS_FALSE;
|
1212
|
+
if (JS_ISIDSTART(c) ||
|
1213
|
+
(c == '\\' &&
|
1214
|
+
(qc = GetUnicodeEscape(ts),
|
1215
|
+
hadUnicodeEscape = JS_ISIDSTART(qc)))) {
|
1216
|
+
if (hadUnicodeEscape)
|
1217
|
+
c = qc;
|
1218
|
+
INIT_TOKENBUF();
|
1219
|
+
for (;;) {
|
1220
|
+
ADD_TO_TOKENBUF(c);
|
1221
|
+
c = GetChar(ts);
|
1222
|
+
if (c == '\\') {
|
1223
|
+
qc = GetUnicodeEscape(ts);
|
1224
|
+
if (!JS_ISIDENT(qc))
|
1225
|
+
break;
|
1226
|
+
c = qc;
|
1227
|
+
hadUnicodeEscape = JS_TRUE;
|
1228
|
+
} else {
|
1229
|
+
if (!JS_ISIDENT(c))
|
1230
|
+
break;
|
1231
|
+
}
|
1232
|
+
}
|
1233
|
+
UngetChar(ts, c);
|
1234
|
+
|
1235
|
+
/*
|
1236
|
+
* Check for keywords unless we saw Unicode escape or parser asks
|
1237
|
+
* to ignore keywords.
|
1238
|
+
*/
|
1239
|
+
if (!hadUnicodeEscape &&
|
1240
|
+
!(ts->flags & TSF_KEYWORD_IS_NAME) &&
|
1241
|
+
TOKENBUF_OK() &&
|
1242
|
+
(kw = FindKeyword(TOKENBUF_BASE(), TOKENBUF_LENGTH()))) {
|
1243
|
+
if (kw->tokentype == TOK_RESERVED) {
|
1244
|
+
if (!js_ReportCompileErrorNumber(cx, ts, NULL,
|
1245
|
+
JSREPORT_WARNING |
|
1246
|
+
JSREPORT_STRICT,
|
1247
|
+
JSMSG_RESERVED_ID,
|
1248
|
+
kw->chars)) {
|
1249
|
+
goto error;
|
1250
|
+
}
|
1251
|
+
} else if (kw->version <= JSVERSION_NUMBER(cx)) {
|
1252
|
+
tt = kw->tokentype;
|
1253
|
+
tp->t_op = (JSOp) kw->op;
|
1254
|
+
goto out;
|
1255
|
+
}
|
1256
|
+
}
|
1257
|
+
|
1258
|
+
atom = TOKENBUF_TO_ATOM();
|
1259
|
+
if (!atom)
|
1260
|
+
goto error;
|
1261
|
+
tp->t_op = JSOP_NAME;
|
1262
|
+
tp->t_atom = atom;
|
1263
|
+
tt = TOK_NAME;
|
1264
|
+
goto out;
|
1265
|
+
}
|
1266
|
+
|
1267
|
+
if (JS7_ISDEC(c) || (c == '.' && JS7_ISDEC(PeekChar(ts)))) {
|
1268
|
+
jsint radix;
|
1269
|
+
const jschar *endptr;
|
1270
|
+
jsdouble dval;
|
1271
|
+
|
1272
|
+
radix = 10;
|
1273
|
+
INIT_TOKENBUF();
|
1274
|
+
|
1275
|
+
if (c == '0') {
|
1276
|
+
ADD_TO_TOKENBUF(c);
|
1277
|
+
c = GetChar(ts);
|
1278
|
+
if (JS_TOLOWER(c) == 'x') {
|
1279
|
+
ADD_TO_TOKENBUF(c);
|
1280
|
+
c = GetChar(ts);
|
1281
|
+
radix = 16;
|
1282
|
+
} else if (JS7_ISDEC(c)) {
|
1283
|
+
radix = 8;
|
1284
|
+
}
|
1285
|
+
}
|
1286
|
+
|
1287
|
+
while (JS7_ISHEX(c)) {
|
1288
|
+
if (radix < 16) {
|
1289
|
+
if (JS7_ISLET(c))
|
1290
|
+
break;
|
1291
|
+
|
1292
|
+
/*
|
1293
|
+
* We permit 08 and 09 as decimal numbers, which makes our
|
1294
|
+
* behaviour a superset of the ECMA numeric grammar. We might
|
1295
|
+
* not always be so permissive, so we warn about it.
|
1296
|
+
*/
|
1297
|
+
if (radix == 8 && c >= '8') {
|
1298
|
+
if (!js_ReportCompileErrorNumber(cx, ts, NULL,
|
1299
|
+
JSREPORT_WARNING,
|
1300
|
+
JSMSG_BAD_OCTAL,
|
1301
|
+
c == '8' ? "08" : "09")) {
|
1302
|
+
goto error;
|
1303
|
+
}
|
1304
|
+
radix = 10;
|
1305
|
+
}
|
1306
|
+
}
|
1307
|
+
ADD_TO_TOKENBUF(c);
|
1308
|
+
c = GetChar(ts);
|
1309
|
+
}
|
1310
|
+
|
1311
|
+
if (radix == 10 && (c == '.' || JS_TOLOWER(c) == 'e')) {
|
1312
|
+
if (c == '.') {
|
1313
|
+
do {
|
1314
|
+
ADD_TO_TOKENBUF(c);
|
1315
|
+
c = GetChar(ts);
|
1316
|
+
} while (JS7_ISDEC(c));
|
1317
|
+
}
|
1318
|
+
if (JS_TOLOWER(c) == 'e') {
|
1319
|
+
ADD_TO_TOKENBUF(c);
|
1320
|
+
c = GetChar(ts);
|
1321
|
+
if (c == '+' || c == '-') {
|
1322
|
+
ADD_TO_TOKENBUF(c);
|
1323
|
+
c = GetChar(ts);
|
1324
|
+
}
|
1325
|
+
if (!JS7_ISDEC(c)) {
|
1326
|
+
js_ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR,
|
1327
|
+
JSMSG_MISSING_EXPONENT);
|
1328
|
+
goto error;
|
1329
|
+
}
|
1330
|
+
do {
|
1331
|
+
ADD_TO_TOKENBUF(c);
|
1332
|
+
c = GetChar(ts);
|
1333
|
+
} while (JS7_ISDEC(c));
|
1334
|
+
}
|
1335
|
+
}
|
1336
|
+
|
1337
|
+
/* Put back the next char and NUL-terminate tokenbuf for js_strto*. */
|
1338
|
+
UngetChar(ts, c);
|
1339
|
+
ADD_TO_TOKENBUF(0);
|
1340
|
+
|
1341
|
+
if (!TOKENBUF_OK())
|
1342
|
+
goto error;
|
1343
|
+
if (radix == 10) {
|
1344
|
+
if (!js_strtod(cx, TOKENBUF_BASE(), TOKENBUF_END(),
|
1345
|
+
&endptr, &dval)) {
|
1346
|
+
js_ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR,
|
1347
|
+
JSMSG_OUT_OF_MEMORY);
|
1348
|
+
goto error;
|
1349
|
+
}
|
1350
|
+
} else {
|
1351
|
+
if (!js_strtointeger(cx, TOKENBUF_BASE(), TOKENBUF_END(),
|
1352
|
+
&endptr, radix, &dval)) {
|
1353
|
+
js_ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR,
|
1354
|
+
JSMSG_OUT_OF_MEMORY);
|
1355
|
+
goto error;
|
1356
|
+
}
|
1357
|
+
}
|
1358
|
+
tp->t_dval = dval;
|
1359
|
+
tt = TOK_NUMBER;
|
1360
|
+
goto out;
|
1361
|
+
}
|
1362
|
+
|
1363
|
+
if (c == '"' || c == '\'') {
|
1364
|
+
qc = c;
|
1365
|
+
INIT_TOKENBUF();
|
1366
|
+
while ((c = GetChar(ts)) != qc) {
|
1367
|
+
if (c == '\n' || c == EOF) {
|
1368
|
+
UngetChar(ts, c);
|
1369
|
+
js_ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR,
|
1370
|
+
JSMSG_UNTERMINATED_STRING);
|
1371
|
+
goto error;
|
1372
|
+
}
|
1373
|
+
if (c == '\\') {
|
1374
|
+
switch (c = GetChar(ts)) {
|
1375
|
+
case 'b': c = '\b'; break;
|
1376
|
+
case 'f': c = '\f'; break;
|
1377
|
+
case 'n': c = '\n'; break;
|
1378
|
+
case 'r': c = '\r'; break;
|
1379
|
+
case 't': c = '\t'; break;
|
1380
|
+
case 'v': c = '\v'; break;
|
1381
|
+
|
1382
|
+
default:
|
1383
|
+
if ('0' <= c && c < '8') {
|
1384
|
+
int32 val = JS7_UNDEC(c);
|
1385
|
+
|
1386
|
+
c = PeekChar(ts);
|
1387
|
+
if ('0' <= c && c < '8') {
|
1388
|
+
val = 8 * val + JS7_UNDEC(c);
|
1389
|
+
GetChar(ts);
|
1390
|
+
c = PeekChar(ts);
|
1391
|
+
if ('0' <= c && c < '8') {
|
1392
|
+
int32 save = val;
|
1393
|
+
val = 8 * val + JS7_UNDEC(c);
|
1394
|
+
if (val <= 0377)
|
1395
|
+
GetChar(ts);
|
1396
|
+
else
|
1397
|
+
val = save;
|
1398
|
+
}
|
1399
|
+
}
|
1400
|
+
|
1401
|
+
c = (jschar)val;
|
1402
|
+
} else if (c == 'u') {
|
1403
|
+
jschar cp[4];
|
1404
|
+
if (PeekChars(ts, 4, cp) &&
|
1405
|
+
JS7_ISHEX(cp[0]) && JS7_ISHEX(cp[1]) &&
|
1406
|
+
JS7_ISHEX(cp[2]) && JS7_ISHEX(cp[3])) {
|
1407
|
+
c = (((((JS7_UNHEX(cp[0]) << 4)
|
1408
|
+
+ JS7_UNHEX(cp[1])) << 4)
|
1409
|
+
+ JS7_UNHEX(cp[2])) << 4)
|
1410
|
+
+ JS7_UNHEX(cp[3]);
|
1411
|
+
SkipChars(ts, 4);
|
1412
|
+
}
|
1413
|
+
} else if (c == 'x') {
|
1414
|
+
jschar cp[2];
|
1415
|
+
if (PeekChars(ts, 2, cp) &&
|
1416
|
+
JS7_ISHEX(cp[0]) && JS7_ISHEX(cp[1])) {
|
1417
|
+
c = (JS7_UNHEX(cp[0]) << 4) + JS7_UNHEX(cp[1]);
|
1418
|
+
SkipChars(ts, 2);
|
1419
|
+
}
|
1420
|
+
} else if (c == '\n') {
|
1421
|
+
/* ECMA follows C by removing escaped newlines. */
|
1422
|
+
continue;
|
1423
|
+
}
|
1424
|
+
break;
|
1425
|
+
}
|
1426
|
+
}
|
1427
|
+
ADD_TO_TOKENBUF(c);
|
1428
|
+
}
|
1429
|
+
atom = TOKENBUF_TO_ATOM();
|
1430
|
+
if (!atom)
|
1431
|
+
goto error;
|
1432
|
+
tp->pos.end.lineno = (uint16)ts->lineno;
|
1433
|
+
tp->t_op = JSOP_STRING;
|
1434
|
+
tp->t_atom = atom;
|
1435
|
+
tt = TOK_STRING;
|
1436
|
+
goto out;
|
1437
|
+
}
|
1438
|
+
|
1439
|
+
switch (c) {
|
1440
|
+
case '\n': tt = TOK_EOL; goto eol_out;
|
1441
|
+
case ';': tt = TOK_SEMI; break;
|
1442
|
+
case '[': tt = TOK_LB; break;
|
1443
|
+
case ']': tt = TOK_RB; break;
|
1444
|
+
case '{': tt = TOK_LC; break;
|
1445
|
+
case '}': tt = TOK_RC; break;
|
1446
|
+
case '(': tt = TOK_LP; break;
|
1447
|
+
case ')': tt = TOK_RP; break;
|
1448
|
+
case ',': tt = TOK_COMMA; break;
|
1449
|
+
case '?': tt = TOK_HOOK; break;
|
1450
|
+
|
1451
|
+
case '.':
|
1452
|
+
#if JS_HAS_XML_SUPPORT
|
1453
|
+
if (MatchChar(ts, c))
|
1454
|
+
tt = TOK_DBLDOT;
|
1455
|
+
else
|
1456
|
+
#endif
|
1457
|
+
tt = TOK_DOT;
|
1458
|
+
break;
|
1459
|
+
|
1460
|
+
case ':':
|
1461
|
+
#if JS_HAS_XML_SUPPORT
|
1462
|
+
if (MatchChar(ts, c)) {
|
1463
|
+
tt = TOK_DBLCOLON;
|
1464
|
+
break;
|
1465
|
+
}
|
1466
|
+
#endif
|
1467
|
+
/*
|
1468
|
+
* Default so compiler can modify to JSOP_GETTER if 'p getter: v' in an
|
1469
|
+
* object initializer, likewise for setter.
|
1470
|
+
*/
|
1471
|
+
tp->t_op = JSOP_NOP;
|
1472
|
+
tt = TOK_COLON;
|
1473
|
+
break;
|
1474
|
+
|
1475
|
+
case '|':
|
1476
|
+
if (MatchChar(ts, c)) {
|
1477
|
+
tt = TOK_OR;
|
1478
|
+
} else if (MatchChar(ts, '=')) {
|
1479
|
+
tp->t_op = JSOP_BITOR;
|
1480
|
+
tt = TOK_ASSIGN;
|
1481
|
+
} else {
|
1482
|
+
tt = TOK_BITOR;
|
1483
|
+
}
|
1484
|
+
break;
|
1485
|
+
|
1486
|
+
case '^':
|
1487
|
+
if (MatchChar(ts, '=')) {
|
1488
|
+
tp->t_op = JSOP_BITXOR;
|
1489
|
+
tt = TOK_ASSIGN;
|
1490
|
+
} else {
|
1491
|
+
tt = TOK_BITXOR;
|
1492
|
+
}
|
1493
|
+
break;
|
1494
|
+
|
1495
|
+
case '&':
|
1496
|
+
if (MatchChar(ts, c)) {
|
1497
|
+
tt = TOK_AND;
|
1498
|
+
} else if (MatchChar(ts, '=')) {
|
1499
|
+
tp->t_op = JSOP_BITAND;
|
1500
|
+
tt = TOK_ASSIGN;
|
1501
|
+
} else {
|
1502
|
+
tt = TOK_BITAND;
|
1503
|
+
}
|
1504
|
+
break;
|
1505
|
+
|
1506
|
+
case '=':
|
1507
|
+
if (MatchChar(ts, c)) {
|
1508
|
+
tp->t_op = MatchChar(ts, c) ? JSOP_STRICTEQ : JSOP_EQ;
|
1509
|
+
tt = TOK_EQOP;
|
1510
|
+
} else {
|
1511
|
+
tp->t_op = JSOP_NOP;
|
1512
|
+
tt = TOK_ASSIGN;
|
1513
|
+
}
|
1514
|
+
break;
|
1515
|
+
|
1516
|
+
case '!':
|
1517
|
+
if (MatchChar(ts, '=')) {
|
1518
|
+
tp->t_op = MatchChar(ts, '=') ? JSOP_STRICTNE : JSOP_NE;
|
1519
|
+
tt = TOK_EQOP;
|
1520
|
+
} else {
|
1521
|
+
tp->t_op = JSOP_NOT;
|
1522
|
+
tt = TOK_UNARYOP;
|
1523
|
+
}
|
1524
|
+
break;
|
1525
|
+
|
1526
|
+
#if JS_HAS_XML_SUPPORT
|
1527
|
+
case '@':
|
1528
|
+
tt = TOK_AT;
|
1529
|
+
break;
|
1530
|
+
#endif
|
1531
|
+
|
1532
|
+
case '<':
|
1533
|
+
#if JS_HAS_XML_SUPPORT
|
1534
|
+
/*
|
1535
|
+
* After much testing, it's clear that Postel's advice to protocol
|
1536
|
+
* designers ("be liberal in what you accept, and conservative in what
|
1537
|
+
* you send") invites a natural-law repercussion for JS as "protocol":
|
1538
|
+
*
|
1539
|
+
* "If you are liberal in what you accept, others will utterly fail to
|
1540
|
+
* be conservative in what they send."
|
1541
|
+
*
|
1542
|
+
* Which means you will get <!-- comments to end of line in the middle
|
1543
|
+
* of .js files, and after if conditions whose then statements are on
|
1544
|
+
* the next line, and other wonders. See at least the following bugs:
|
1545
|
+
* https://bugzilla.mozilla.org/show_bug.cgi?id=309242
|
1546
|
+
* https://bugzilla.mozilla.org/show_bug.cgi?id=309712
|
1547
|
+
* https://bugzilla.mozilla.org/show_bug.cgi?id=310993
|
1548
|
+
*
|
1549
|
+
* So without JSOPTION_XML, we never scan an XML comment or CDATA
|
1550
|
+
* literal. We always scan <! as the start of an HTML comment hack
|
1551
|
+
* to end of line, used since Netscape 2 to hide script tag content
|
1552
|
+
* from script-unaware browsers.
|
1553
|
+
*/
|
1554
|
+
if ((ts->flags & TSF_OPERAND) &&
|
1555
|
+
(JS_HAS_XML_OPTION(cx) || PeekChar(ts) != '!')) {
|
1556
|
+
/* Check for XML comment or CDATA section. */
|
1557
|
+
if (MatchChar(ts, '!')) {
|
1558
|
+
INIT_TOKENBUF();
|
1559
|
+
|
1560
|
+
/* Scan XML comment. */
|
1561
|
+
if (MatchChar(ts, '-')) {
|
1562
|
+
if (!MatchChar(ts, '-'))
|
1563
|
+
goto bad_xml_markup;
|
1564
|
+
while ((c = GetChar(ts)) != '-' || !MatchChar(ts, '-')) {
|
1565
|
+
if (c == EOF)
|
1566
|
+
goto bad_xml_markup;
|
1567
|
+
ADD_TO_TOKENBUF(c);
|
1568
|
+
}
|
1569
|
+
tt = TOK_XMLCOMMENT;
|
1570
|
+
tp->t_op = JSOP_XMLCOMMENT;
|
1571
|
+
goto finish_xml_markup;
|
1572
|
+
}
|
1573
|
+
|
1574
|
+
/* Scan CDATA section. */
|
1575
|
+
if (MatchChar(ts, '[')) {
|
1576
|
+
jschar cp[6];
|
1577
|
+
if (PeekChars(ts, 6, cp) &&
|
1578
|
+
cp[0] == 'C' &&
|
1579
|
+
cp[1] == 'D' &&
|
1580
|
+
cp[2] == 'A' &&
|
1581
|
+
cp[3] == 'T' &&
|
1582
|
+
cp[4] == 'A' &&
|
1583
|
+
cp[5] == '[') {
|
1584
|
+
SkipChars(ts, 6);
|
1585
|
+
while ((c = GetChar(ts)) != ']' ||
|
1586
|
+
!PeekChars(ts, 2, cp) ||
|
1587
|
+
cp[0] != ']' ||
|
1588
|
+
cp[1] != '>') {
|
1589
|
+
if (c == EOF)
|
1590
|
+
goto bad_xml_markup;
|
1591
|
+
ADD_TO_TOKENBUF(c);
|
1592
|
+
}
|
1593
|
+
GetChar(ts); /* discard ] but not > */
|
1594
|
+
tt = TOK_XMLCDATA;
|
1595
|
+
tp->t_op = JSOP_XMLCDATA;
|
1596
|
+
goto finish_xml_markup;
|
1597
|
+
}
|
1598
|
+
goto bad_xml_markup;
|
1599
|
+
}
|
1600
|
+
}
|
1601
|
+
|
1602
|
+
/* Check for processing instruction. */
|
1603
|
+
if (MatchChar(ts, '?')) {
|
1604
|
+
inTarget = JS_TRUE;
|
1605
|
+
targetLength = 0;
|
1606
|
+
contentIndex = -1;
|
1607
|
+
|
1608
|
+
INIT_TOKENBUF();
|
1609
|
+
while ((c = GetChar(ts)) != '?' || PeekChar(ts) != '>') {
|
1610
|
+
if (c == EOF)
|
1611
|
+
goto bad_xml_markup;
|
1612
|
+
if (inTarget) {
|
1613
|
+
if (JS_ISXMLSPACE(c)) {
|
1614
|
+
if (TOKENBUF_LENGTH() == 0)
|
1615
|
+
goto bad_xml_markup;
|
1616
|
+
inTarget = JS_FALSE;
|
1617
|
+
} else {
|
1618
|
+
if (!((TOKENBUF_LENGTH() == 0)
|
1619
|
+
? JS_ISXMLNSSTART(c)
|
1620
|
+
: JS_ISXMLNS(c))) {
|
1621
|
+
goto bad_xml_markup;
|
1622
|
+
}
|
1623
|
+
++targetLength;
|
1624
|
+
}
|
1625
|
+
} else {
|
1626
|
+
if (contentIndex < 0 && !JS_ISXMLSPACE(c))
|
1627
|
+
contentIndex = TOKENBUF_LENGTH();
|
1628
|
+
}
|
1629
|
+
ADD_TO_TOKENBUF(c);
|
1630
|
+
}
|
1631
|
+
if (targetLength == 0)
|
1632
|
+
goto bad_xml_markup;
|
1633
|
+
if (!TOKENBUF_OK())
|
1634
|
+
goto error;
|
1635
|
+
if (contentIndex < 0) {
|
1636
|
+
atom = cx->runtime->atomState.emptyAtom;
|
1637
|
+
} else {
|
1638
|
+
atom = js_AtomizeChars(cx,
|
1639
|
+
&TOKENBUF_CHAR(contentIndex),
|
1640
|
+
TOKENBUF_LENGTH() - contentIndex,
|
1641
|
+
0);
|
1642
|
+
if (!atom)
|
1643
|
+
goto error;
|
1644
|
+
}
|
1645
|
+
TRIM_TOKENBUF(targetLength);
|
1646
|
+
tp->t_atom2 = atom;
|
1647
|
+
tt = TOK_XMLPI;
|
1648
|
+
|
1649
|
+
finish_xml_markup:
|
1650
|
+
if (!MatchChar(ts, '>'))
|
1651
|
+
goto bad_xml_markup;
|
1652
|
+
atom = TOKENBUF_TO_ATOM();
|
1653
|
+
if (!atom)
|
1654
|
+
goto error;
|
1655
|
+
tp->t_atom = atom;
|
1656
|
+
tp->pos.end.lineno = (uint16)ts->lineno;
|
1657
|
+
goto out;
|
1658
|
+
}
|
1659
|
+
|
1660
|
+
/* An XML start-of-tag character. */
|
1661
|
+
tt = MatchChar(ts, '/') ? TOK_XMLETAGO : TOK_XMLSTAGO;
|
1662
|
+
goto out;
|
1663
|
+
|
1664
|
+
bad_xml_markup:
|
1665
|
+
js_ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR,
|
1666
|
+
JSMSG_BAD_XML_MARKUP);
|
1667
|
+
goto error;
|
1668
|
+
}
|
1669
|
+
#endif /* JS_HAS_XML_SUPPORT */
|
1670
|
+
|
1671
|
+
/* NB: treat HTML begin-comment as comment-till-end-of-line */
|
1672
|
+
if (MatchChar(ts, '!')) {
|
1673
|
+
if (MatchChar(ts, '-')) {
|
1674
|
+
if (MatchChar(ts, '-')) {
|
1675
|
+
ts->flags |= TSF_IN_HTML_COMMENT;
|
1676
|
+
goto skipline;
|
1677
|
+
}
|
1678
|
+
UngetChar(ts, '-');
|
1679
|
+
}
|
1680
|
+
UngetChar(ts, '!');
|
1681
|
+
}
|
1682
|
+
if (MatchChar(ts, c)) {
|
1683
|
+
tp->t_op = JSOP_LSH;
|
1684
|
+
tt = MatchChar(ts, '=') ? TOK_ASSIGN : TOK_SHOP;
|
1685
|
+
} else {
|
1686
|
+
tp->t_op = MatchChar(ts, '=') ? JSOP_LE : JSOP_LT;
|
1687
|
+
tt = TOK_RELOP;
|
1688
|
+
}
|
1689
|
+
break;
|
1690
|
+
|
1691
|
+
case '>':
|
1692
|
+
if (MatchChar(ts, c)) {
|
1693
|
+
tp->t_op = MatchChar(ts, c) ? JSOP_URSH : JSOP_RSH;
|
1694
|
+
tt = MatchChar(ts, '=') ? TOK_ASSIGN : TOK_SHOP;
|
1695
|
+
} else {
|
1696
|
+
tp->t_op = MatchChar(ts, '=') ? JSOP_GE : JSOP_GT;
|
1697
|
+
tt = TOK_RELOP;
|
1698
|
+
}
|
1699
|
+
break;
|
1700
|
+
|
1701
|
+
case '*':
|
1702
|
+
tp->t_op = JSOP_MUL;
|
1703
|
+
tt = MatchChar(ts, '=') ? TOK_ASSIGN : TOK_STAR;
|
1704
|
+
break;
|
1705
|
+
|
1706
|
+
case '/':
|
1707
|
+
if (MatchChar(ts, '/')) {
|
1708
|
+
/*
|
1709
|
+
* Hack for source filters such as the Mozilla XUL preprocessor:
|
1710
|
+
* "//@line 123\n" sets the number of the *next* line after the
|
1711
|
+
* comment to 123.
|
1712
|
+
*/
|
1713
|
+
if (JS_HAS_ATLINE_OPTION(cx)) {
|
1714
|
+
jschar cp[5];
|
1715
|
+
uintN i, line, temp;
|
1716
|
+
char filename[1024];
|
1717
|
+
|
1718
|
+
if (PeekChars(ts, 5, cp) &&
|
1719
|
+
cp[0] == '@' &&
|
1720
|
+
cp[1] == 'l' &&
|
1721
|
+
cp[2] == 'i' &&
|
1722
|
+
cp[3] == 'n' &&
|
1723
|
+
cp[4] == 'e') {
|
1724
|
+
SkipChars(ts, 5);
|
1725
|
+
while ((c = GetChar(ts)) != '\n' && JS_ISSPACE(c))
|
1726
|
+
continue;
|
1727
|
+
if (JS7_ISDEC(c)) {
|
1728
|
+
line = JS7_UNDEC(c);
|
1729
|
+
while ((c = GetChar(ts)) != EOF && JS7_ISDEC(c)) {
|
1730
|
+
temp = 10 * line + JS7_UNDEC(c);
|
1731
|
+
if (temp < line) {
|
1732
|
+
/* Ignore overlarge line numbers. */
|
1733
|
+
goto skipline;
|
1734
|
+
}
|
1735
|
+
line = temp;
|
1736
|
+
}
|
1737
|
+
while (c != '\n' && JS_ISSPACE(c))
|
1738
|
+
c = GetChar(ts);
|
1739
|
+
i = 0;
|
1740
|
+
if (c == '"') {
|
1741
|
+
while ((c = GetChar(ts)) != EOF && c != '"') {
|
1742
|
+
if (c == '\n') {
|
1743
|
+
UngetChar(ts, c);
|
1744
|
+
goto skipline;
|
1745
|
+
}
|
1746
|
+
if ((c >> 8) != 0 || i >= sizeof filename - 1)
|
1747
|
+
goto skipline;
|
1748
|
+
filename[i++] = (char) c;
|
1749
|
+
}
|
1750
|
+
if (c == '"') {
|
1751
|
+
while ((c = GetChar(ts)) != '\n' &&
|
1752
|
+
JS_ISSPACE(c)) {
|
1753
|
+
continue;
|
1754
|
+
}
|
1755
|
+
}
|
1756
|
+
}
|
1757
|
+
filename[i] = '\0';
|
1758
|
+
if (c == '\n') {
|
1759
|
+
if (i > 0) {
|
1760
|
+
if (ts->flags & TSF_OWNFILENAME)
|
1761
|
+
JS_free(cx, (void *) ts->filename);
|
1762
|
+
ts->filename = JS_strdup(cx, filename);
|
1763
|
+
if (!ts->filename)
|
1764
|
+
goto error;
|
1765
|
+
ts->flags |= TSF_OWNFILENAME;
|
1766
|
+
}
|
1767
|
+
ts->lineno = line;
|
1768
|
+
}
|
1769
|
+
}
|
1770
|
+
UngetChar(ts, c);
|
1771
|
+
}
|
1772
|
+
}
|
1773
|
+
|
1774
|
+
skipline:
|
1775
|
+
/* Optimize line skipping if we are not in an HTML comment. */
|
1776
|
+
if (ts->flags & TSF_IN_HTML_COMMENT) {
|
1777
|
+
while ((c = GetChar(ts)) != EOF && c != '\n') {
|
1778
|
+
if (c == '-' && MatchChar(ts, '-') && MatchChar(ts, '>'))
|
1779
|
+
ts->flags &= ~TSF_IN_HTML_COMMENT;
|
1780
|
+
}
|
1781
|
+
} else {
|
1782
|
+
while ((c = GetChar(ts)) != EOF && c != '\n')
|
1783
|
+
continue;
|
1784
|
+
}
|
1785
|
+
UngetChar(ts, c);
|
1786
|
+
ts->cursor = (ts->cursor - 1) & NTOKENS_MASK;
|
1787
|
+
goto retry;
|
1788
|
+
}
|
1789
|
+
|
1790
|
+
if (MatchChar(ts, '*')) {
|
1791
|
+
while ((c = GetChar(ts)) != EOF &&
|
1792
|
+
!(c == '*' && MatchChar(ts, '/'))) {
|
1793
|
+
/* Ignore all characters until comment close. */
|
1794
|
+
}
|
1795
|
+
if (c == EOF) {
|
1796
|
+
js_ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR,
|
1797
|
+
JSMSG_UNTERMINATED_COMMENT);
|
1798
|
+
goto error;
|
1799
|
+
}
|
1800
|
+
ts->cursor = (ts->cursor - 1) & NTOKENS_MASK;
|
1801
|
+
goto retry;
|
1802
|
+
}
|
1803
|
+
|
1804
|
+
if (ts->flags & TSF_OPERAND) {
|
1805
|
+
uintN flags;
|
1806
|
+
JSBool inCharClass = JS_FALSE;
|
1807
|
+
|
1808
|
+
INIT_TOKENBUF();
|
1809
|
+
for (;;) {
|
1810
|
+
c = GetChar(ts);
|
1811
|
+
if (c == '\n' || c == EOF) {
|
1812
|
+
UngetChar(ts, c);
|
1813
|
+
js_ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR,
|
1814
|
+
JSMSG_UNTERMINATED_REGEXP);
|
1815
|
+
goto error;
|
1816
|
+
}
|
1817
|
+
if (c == '\\') {
|
1818
|
+
ADD_TO_TOKENBUF(c);
|
1819
|
+
c = GetChar(ts);
|
1820
|
+
} else if (c == '[') {
|
1821
|
+
inCharClass = JS_TRUE;
|
1822
|
+
} else if (c == ']') {
|
1823
|
+
inCharClass = JS_FALSE;
|
1824
|
+
} else if (c == '/' && !inCharClass) {
|
1825
|
+
/* For compat with IE, allow unescaped / in char classes. */
|
1826
|
+
break;
|
1827
|
+
}
|
1828
|
+
ADD_TO_TOKENBUF(c);
|
1829
|
+
}
|
1830
|
+
for (flags = 0; ; ) {
|
1831
|
+
c = PeekChar(ts);
|
1832
|
+
if (c == 'g')
|
1833
|
+
flags |= JSREG_GLOB;
|
1834
|
+
else if (c == 'i')
|
1835
|
+
flags |= JSREG_FOLD;
|
1836
|
+
else if (c == 'm')
|
1837
|
+
flags |= JSREG_MULTILINE;
|
1838
|
+
else if (c == 'y')
|
1839
|
+
flags |= JSREG_STICKY;
|
1840
|
+
else
|
1841
|
+
break;
|
1842
|
+
GetChar(ts);
|
1843
|
+
}
|
1844
|
+
c = PeekChar(ts);
|
1845
|
+
if (JS7_ISLET(c)) {
|
1846
|
+
tp->ptr = ts->linebuf.ptr - 1;
|
1847
|
+
js_ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR,
|
1848
|
+
JSMSG_BAD_REGEXP_FLAG);
|
1849
|
+
(void) GetChar(ts);
|
1850
|
+
goto error;
|
1851
|
+
}
|
1852
|
+
/* XXXbe fix jsregexp.c so it doesn't depend on NUL termination */
|
1853
|
+
if (!TOKENBUF_OK())
|
1854
|
+
goto error;
|
1855
|
+
NUL_TERM_TOKENBUF();
|
1856
|
+
tp->t_reflags = flags;
|
1857
|
+
tt = TOK_REGEXP;
|
1858
|
+
break;
|
1859
|
+
}
|
1860
|
+
|
1861
|
+
tp->t_op = JSOP_DIV;
|
1862
|
+
tt = MatchChar(ts, '=') ? TOK_ASSIGN : TOK_DIVOP;
|
1863
|
+
break;
|
1864
|
+
|
1865
|
+
case '%':
|
1866
|
+
tp->t_op = JSOP_MOD;
|
1867
|
+
tt = MatchChar(ts, '=') ? TOK_ASSIGN : TOK_DIVOP;
|
1868
|
+
break;
|
1869
|
+
|
1870
|
+
case '~':
|
1871
|
+
tp->t_op = JSOP_BITNOT;
|
1872
|
+
tt = TOK_UNARYOP;
|
1873
|
+
break;
|
1874
|
+
|
1875
|
+
case '+':
|
1876
|
+
if (MatchChar(ts, '=')) {
|
1877
|
+
tp->t_op = JSOP_ADD;
|
1878
|
+
tt = TOK_ASSIGN;
|
1879
|
+
} else if (MatchChar(ts, c)) {
|
1880
|
+
tt = TOK_INC;
|
1881
|
+
} else {
|
1882
|
+
tp->t_op = JSOP_POS;
|
1883
|
+
tt = TOK_PLUS;
|
1884
|
+
}
|
1885
|
+
break;
|
1886
|
+
|
1887
|
+
case '-':
|
1888
|
+
if (MatchChar(ts, '=')) {
|
1889
|
+
tp->t_op = JSOP_SUB;
|
1890
|
+
tt = TOK_ASSIGN;
|
1891
|
+
} else if (MatchChar(ts, c)) {
|
1892
|
+
if (PeekChar(ts) == '>' && !(ts->flags & TSF_DIRTYLINE)) {
|
1893
|
+
ts->flags &= ~TSF_IN_HTML_COMMENT;
|
1894
|
+
goto skipline;
|
1895
|
+
}
|
1896
|
+
tt = TOK_DEC;
|
1897
|
+
} else {
|
1898
|
+
tp->t_op = JSOP_NEG;
|
1899
|
+
tt = TOK_MINUS;
|
1900
|
+
}
|
1901
|
+
break;
|
1902
|
+
|
1903
|
+
#if JS_HAS_SHARP_VARS
|
1904
|
+
case '#':
|
1905
|
+
{
|
1906
|
+
uint32 n;
|
1907
|
+
|
1908
|
+
c = GetChar(ts);
|
1909
|
+
if (!JS7_ISDEC(c)) {
|
1910
|
+
UngetChar(ts, c);
|
1911
|
+
goto badchar;
|
1912
|
+
}
|
1913
|
+
n = (uint32)JS7_UNDEC(c);
|
1914
|
+
for (;;) {
|
1915
|
+
c = GetChar(ts);
|
1916
|
+
if (!JS7_ISDEC(c))
|
1917
|
+
break;
|
1918
|
+
n = 10 * n + JS7_UNDEC(c);
|
1919
|
+
if (n >= UINT16_LIMIT) {
|
1920
|
+
js_ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR,
|
1921
|
+
JSMSG_SHARPVAR_TOO_BIG);
|
1922
|
+
goto error;
|
1923
|
+
}
|
1924
|
+
}
|
1925
|
+
tp->t_dval = (jsdouble) n;
|
1926
|
+
if (JS_HAS_STRICT_OPTION(cx) &&
|
1927
|
+
(c == '=' || c == '#')) {
|
1928
|
+
char buf[20];
|
1929
|
+
JS_snprintf(buf, sizeof buf, "#%u%c", n, c);
|
1930
|
+
if (!js_ReportCompileErrorNumber(cx, ts, NULL,
|
1931
|
+
JSREPORT_WARNING |
|
1932
|
+
JSREPORT_STRICT,
|
1933
|
+
JSMSG_DEPRECATED_USAGE,
|
1934
|
+
buf)) {
|
1935
|
+
goto error;
|
1936
|
+
}
|
1937
|
+
}
|
1938
|
+
if (c == '=')
|
1939
|
+
tt = TOK_DEFSHARP;
|
1940
|
+
else if (c == '#')
|
1941
|
+
tt = TOK_USESHARP;
|
1942
|
+
else
|
1943
|
+
goto badchar;
|
1944
|
+
break;
|
1945
|
+
}
|
1946
|
+
#endif /* JS_HAS_SHARP_VARS */
|
1947
|
+
|
1948
|
+
#if JS_HAS_SHARP_VARS || JS_HAS_XML_SUPPORT
|
1949
|
+
badchar:
|
1950
|
+
#endif
|
1951
|
+
|
1952
|
+
default:
|
1953
|
+
js_ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR,
|
1954
|
+
JSMSG_ILLEGAL_CHARACTER);
|
1955
|
+
goto error;
|
1956
|
+
}
|
1957
|
+
|
1958
|
+
out:
|
1959
|
+
JS_ASSERT(tt != TOK_EOL);
|
1960
|
+
ts->flags |= TSF_DIRTYLINE;
|
1961
|
+
|
1962
|
+
eol_out:
|
1963
|
+
if (!STRING_BUFFER_OK(&ts->tokenbuf))
|
1964
|
+
tt = TOK_ERROR;
|
1965
|
+
JS_ASSERT(tt < TOK_LIMIT);
|
1966
|
+
tp->pos.end.index = ts->linepos +
|
1967
|
+
PTRDIFF(ts->linebuf.ptr, ts->linebuf.base, jschar) -
|
1968
|
+
ts->ungetpos;
|
1969
|
+
tp->type = tt;
|
1970
|
+
return tt;
|
1971
|
+
|
1972
|
+
error:
|
1973
|
+
tt = TOK_ERROR;
|
1974
|
+
ts->flags |= TSF_ERROR;
|
1975
|
+
goto out;
|
1976
|
+
|
1977
|
+
#undef INIT_TOKENBUF
|
1978
|
+
#undef TOKENBUF_LENGTH
|
1979
|
+
#undef TOKENBUF_OK
|
1980
|
+
#undef TOKENBUF_TO_ATOM
|
1981
|
+
#undef ADD_TO_TOKENBUF
|
1982
|
+
#undef TOKENBUF_BASE
|
1983
|
+
#undef TOKENBUF_CHAR
|
1984
|
+
#undef TRIM_TOKENBUF
|
1985
|
+
#undef NUL_TERM_TOKENBUF
|
1986
|
+
}
|
1987
|
+
|
1988
|
+
void
|
1989
|
+
js_UngetToken(JSTokenStream *ts)
|
1990
|
+
{
|
1991
|
+
JS_ASSERT(ts->lookahead < NTOKENS_MASK);
|
1992
|
+
ts->lookahead++;
|
1993
|
+
ts->cursor = (ts->cursor - 1) & NTOKENS_MASK;
|
1994
|
+
}
|
1995
|
+
|
1996
|
+
JSBool
|
1997
|
+
js_MatchToken(JSContext *cx, JSTokenStream *ts, JSTokenType tt)
|
1998
|
+
{
|
1999
|
+
if (js_GetToken(cx, ts) == tt)
|
2000
|
+
return JS_TRUE;
|
2001
|
+
js_UngetToken(ts);
|
2002
|
+
return JS_FALSE;
|
2003
|
+
}
|