Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Bug 805080 - Remove unused CESU8 support from SpiderMonkey; r=luke

We have many CESU8 paths in SpiderMonkey which are completely unused and
untested. We have many more "UTF-8" paths which are really mislabled CESU8 paths
and visa-versa. This patch attempts to disentable all of the various encoding
options in SpiderMonkey.
  • Loading branch information...
commit 53c97cc6f67184f9cefd0d9fc71ed647b30a5c9c 1 parent 299d760
Terrence Cole terrence2 authored
2  ipc/testshell/XPCShellEnvironment.cpp
@@ -597,7 +597,7 @@ ProcessFile(JSContext *cx,
597 597 }
598 598 bufp += strlen(bufp);
599 599 lineno++;
600   - } while (!JS_BufferIsCompilableUnit(cx, JS_FALSE, obj, buffer, strlen(buffer)));
  600 + } while (!JS_BufferIsCompilableUnit(cx, obj, buffer, strlen(buffer)));
601 601
602 602 /* Clear any pending exception from previous failed compiles. */
603 603 JS_ClearPendingException(cx);
108 js/src/ctypes/CTypes.cpp
@@ -39,6 +39,114 @@ using namespace std;
39 39 namespace js {
40 40 namespace ctypes {
41 41
  42 +size_t
  43 +GetDeflatedUTF8StringLength(JSContext *maybecx, const jschar *chars,
  44 + size_t nchars)
  45 +{
  46 + size_t nbytes;
  47 + const jschar *end;
  48 + unsigned c, c2;
  49 + char buffer[10];
  50 +
  51 + nbytes = nchars;
  52 + for (end = chars + nchars; chars != end; chars++) {
  53 + c = *chars;
  54 + if (c < 0x80)
  55 + continue;
  56 + if (0xD800 <= c && c <= 0xDFFF) {
  57 + /* Surrogate pair. */
  58 + chars++;
  59 +
  60 + /* nbytes sets 1 length since this is surrogate pair. */
  61 + nbytes--;
  62 + if (c >= 0xDC00 || chars == end)
  63 + goto bad_surrogate;
  64 + c2 = *chars;
  65 + if (c2 < 0xDC00 || c2 > 0xDFFF)
  66 + goto bad_surrogate;
  67 + c = ((c - 0xD800) << 10) + (c2 - 0xDC00) + 0x10000;
  68 + }
  69 + c >>= 11;
  70 + nbytes++;
  71 + while (c) {
  72 + c >>= 5;
  73 + nbytes++;
  74 + }
  75 + }
  76 + return nbytes;
  77 +
  78 + bad_surrogate:
  79 + if (maybecx) {
  80 + JS_snprintf(buffer, 10, "0x%x", c);
  81 + JS_ReportErrorFlagsAndNumber(maybecx, JSREPORT_ERROR, js_GetErrorMessage,
  82 + NULL, JSMSG_BAD_SURROGATE_CHAR, buffer);
  83 + }
  84 + return (size_t) -1;
  85 +}
  86 +
  87 +bool
  88 +DeflateStringToUTF8Buffer(JSContext *maybecx, const jschar *src, size_t srclen,
  89 + char *dst, size_t *dstlenp)
  90 +{
  91 + size_t i, utf8Len;
  92 + jschar c, c2;
  93 + uint32_t v;
  94 + uint8_t utf8buf[6];
  95 +
  96 + size_t dstlen = *dstlenp;
  97 + size_t origDstlen = dstlen;
  98 +
  99 + while (srclen) {
  100 + c = *src++;
  101 + srclen--;
  102 + if (c >= 0xDC00 && c <= 0xDFFF)
  103 + goto badSurrogate;
  104 + if (c < 0xD800 || c > 0xDBFF) {
  105 + v = c;
  106 + } else {
  107 + if (srclen < 1)
  108 + goto badSurrogate;
  109 + c2 = *src;
  110 + if ((c2 < 0xDC00) || (c2 > 0xDFFF))
  111 + goto badSurrogate;
  112 + src++;
  113 + srclen--;
  114 + v = ((c - 0xD800) << 10) + (c2 - 0xDC00) + 0x10000;
  115 + }
  116 + if (v < 0x0080) {
  117 + /* no encoding necessary - performance hack */
  118 + if (dstlen == 0)
  119 + goto bufferTooSmall;
  120 + *dst++ = (char) v;
  121 + utf8Len = 1;
  122 + } else {
  123 + utf8Len = js_OneUcs4ToUtf8Char(utf8buf, v);
  124 + if (utf8Len > dstlen)
  125 + goto bufferTooSmall;
  126 + for (i = 0; i < utf8Len; i++)
  127 + *dst++ = (char) utf8buf[i];
  128 + }
  129 + dstlen -= utf8Len;
  130 + }
  131 + *dstlenp = (origDstlen - dstlen);
  132 + return JS_TRUE;
  133 +
  134 +badSurrogate:
  135 + *dstlenp = (origDstlen - dstlen);
  136 + /* Delegate error reporting to the measurement function. */
  137 + if (maybecx)
  138 + GetDeflatedUTF8StringLength(maybecx, src - 1, srclen + 1);
  139 + return JS_FALSE;
  140 +
  141 +bufferTooSmall:
  142 + *dstlenp = (origDstlen - dstlen);
  143 + if (maybecx) {
  144 + JS_ReportErrorNumber(maybecx, js_GetErrorMessage, NULL,
  145 + JSMSG_BUFFER_TOO_SMALL);
  146 + }
  147 + return JS_FALSE;
  148 +}
  149 +
42 150 /*******************************************************************************
43 151 ** JSAPI function prototypes
44 152 *******************************************************************************/
9 js/src/ctypes/CTypes.h
@@ -155,6 +155,15 @@ PrependString(Vector<jschar, N, AP> &v, JSString* str)
155 155 memcpy(v.begin(), chars, alen * sizeof(jschar));
156 156 }
157 157
  158 +extern size_t
  159 +GetDeflatedUTF8StringLength(JSContext *maybecx, const jschar *chars,
  160 + size_t charsLength);
  161 +
  162 +bool
  163 +DeflateStringToUTF8Buffer(JSContext *maybecx, const jschar *src, size_t srclen,
  164 + char *dst, size_t *dstlenp);
  165 +
  166 +
158 167 /*******************************************************************************
159 168 ** Function and struct API definitions
160 169 *******************************************************************************/
1  js/src/jsapi-tests/Makefile.in
@@ -60,7 +60,6 @@ CPPSRCS = \
60 60 testStringBuffer.cpp \
61 61 testTrap.cpp \
62 62 testTypedArrays.cpp \
63   - testUTF8.cpp \
64 63 testValueABI.cpp \
65 64 testVersion.cpp \
66 65 testXDR.cpp \
25 js/src/jsapi-tests/testUTF8.cpp
... ... @@ -1,25 +0,0 @@
1   -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2   - * vim: set ts=8 sw=4 et tw=99:
3   - */
4   -/* This Source Code Form is subject to the terms of the Mozilla Public
5   - * License, v. 2.0. If a copy of the MPL was not distributed with this
6   - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7   -
8   -
9   -#include "tests.h"
10   -
11   -BEGIN_TEST(testUTF8_bug589917)
12   -{
13   - const jschar surrogate_pair[] = { 0xd800, 0xdc00 };
14   - char output_buffer[10];
15   - size_t utf8_len = sizeof(output_buffer);
16   -
17   - CHECK(JS_EncodeCharacters(cx, surrogate_pair, 2, output_buffer, &utf8_len));
18   - CHECK_EQUAL(utf8_len, 4);
19   -
20   - CHECK(JS_EncodeCharacters(cx, surrogate_pair, 2, NULL, &utf8_len));
21   - CHECK_EQUAL(utf8_len, 4);
22   -
23   - return true;
24   -}
25   -END_TEST(testUTF8_bug589917)
10 js/src/jsapi-tests/testXDR.cpp
@@ -25,10 +25,12 @@ CompileScriptForPrincipalsVersionOrigin(JSContext *cx, JS::HandleObject obj,
25 25 if (!chars)
26 26 return NULL;
27 27 JS_ALWAYS_TRUE(JS_DecodeBytes(cx, bytes, nbytes, chars, &nchars));
28   - JSScript *script = JS_CompileUCScriptForPrincipalsVersionOrigin(cx, obj,
29   - principals, originPrincipals,
30   - chars, nchars,
31   - filename, lineno, version);
  28 + JS::CompileOptions options(cx);
  29 + options.setPrincipals(principals)
  30 + .setOriginPrincipals(originPrincipals)
  31 + .setFileAndLine(filename, lineno)
  32 + .setVersion(version);
  33 + JSScript *script = JS::Compile(cx, obj, options, chars, nchars);
32 34 free(chars);
33 35 return script;
34 36 }
2  js/src/jsapi-tests/tests.cpp
@@ -76,8 +76,6 @@ int main(int argc, char *argv[])
76 76 int failures = 0;
77 77 const char *filter = (argc == 2) ? argv[1] : NULL;
78 78
79   - JS_SetCStringsAreUTF8();
80   -
81 79 for (JSAPITest *test = JSAPITest::list; test; test = test->next) {
82 80 const char *name = test->name();
83 81 if (filter && strstr(name, filter) == NULL)
183 js/src/jsapi.cpp
@@ -668,9 +668,8 @@ JS_IsBuiltinFunctionConstructor(JSFunction *fun)
668 668 /************************************************************************/
669 669
670 670 /*
671   - * Has a new runtime ever been created? This flag is used to detect unsafe
672   - * changes to js_CStringsAreUTF8 after a runtime has been created, and to
673   - * control things that should happen only once across all runtimes.
  671 + * Has a new runtime ever been created? This flag is used to control things
  672 + * that should happen only once across all runtimes.
674 673 */
675 674 static JSBool js_NewRuntimeWasCalled = JS_FALSE;
676 675
@@ -5211,7 +5210,7 @@ JS::Compile(JSContext *cx, HandleObject obj, CompileOptions options,
5211 5210 {
5212 5211 jschar *chars;
5213 5212 if (options.utf8)
5214   - chars = InflateString(cx, bytes, &length, CESU8Encoding);
  5213 + chars = InflateUTF8String(cx, bytes, &length);
5215 5214 else
5216 5215 chars = InflateString(cx, bytes, &length);
5217 5216 if (!chars)
@@ -5244,40 +5243,6 @@ JS::Compile(JSContext *cx, HandleObject obj, CompileOptions options, const char
5244 5243 return script;
5245 5244 }
5246 5245
5247   -extern JS_PUBLIC_API(JSScript *)
5248   -JS_CompileUCScriptForPrincipalsVersion(JSContext *cx, JSObject *objArg,
5249   - JSPrincipals *principals,
5250   - const jschar *chars, size_t length,
5251   - const char *filename, unsigned lineno,
5252   - JSVersion version)
5253   -{
5254   - RootedObject obj(cx, objArg);
5255   - CompileOptions options(cx);
5256   - options.setPrincipals(principals)
5257   - .setFileAndLine(filename, lineno)
5258   - .setVersion(version);
5259   -
5260   - return Compile(cx, obj, options, chars, length);
5261   -}
5262   -
5263   -extern JS_PUBLIC_API(JSScript *)
5264   -JS_CompileUCScriptForPrincipalsVersionOrigin(JSContext *cx, JSObject *objArg,
5265   - JSPrincipals *principals,
5266   - JSPrincipals *originPrincipals,
5267   - const jschar *chars, size_t length,
5268   - const char *filename, unsigned lineno,
5269   - JSVersion version)
5270   -{
5271   - RootedObject obj(cx, objArg);
5272   - CompileOptions options(cx);
5273   - options.setPrincipals(principals)
5274   - .setOriginPrincipals(originPrincipals)
5275   - .setFileAndLine(filename, lineno)
5276   - .setVersion(version);
5277   -
5278   - return Compile(cx, obj, options, chars, length);
5279   -}
5280   -
5281 5246 JS_PUBLIC_API(JSScript *)
5282 5247 JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *objArg, JSPrincipals *principals,
5283 5248 const jschar *chars, size_t length,
@@ -5303,25 +5268,9 @@ JS_CompileUCScript(JSContext *cx, JSObject *objArg, const jschar *chars, size_t
5303 5268 }
5304 5269
5305 5270 JS_PUBLIC_API(JSScript *)
5306   -JS_CompileScriptForPrincipalsVersion(JSContext *cx, JSObject *objArg,
5307   - JSPrincipals *principals,
5308   - const char *bytes, size_t length,
5309   - const char *filename, unsigned lineno,
5310   - JSVersion version)
5311   -{
5312   - RootedObject obj(cx, objArg);
5313   - CompileOptions options(cx);
5314   - options.setPrincipals(principals)
5315   - .setFileAndLine(filename, lineno)
5316   - .setVersion(version);
5317   -
5318   - return Compile(cx, obj, options, bytes, length);
5319   -}
5320   -
5321   -JS_PUBLIC_API(JSScript *)
5322 5271 JS_CompileScriptForPrincipals(JSContext *cx, JSObject *objArg,
5323 5272 JSPrincipals *principals,
5324   - const char *bytes, size_t length,
  5273 + const char *ascii, size_t length,
5325 5274 const char *filename, unsigned lineno)
5326 5275 {
5327 5276 RootedObject obj(cx, objArg);
@@ -5329,25 +5278,24 @@ JS_CompileScriptForPrincipals(JSContext *cx, JSObject *objArg,
5329 5278 options.setPrincipals(principals)
5330 5279 .setFileAndLine(filename, lineno);
5331 5280
5332   - return Compile(cx, obj, options, bytes, length);
  5281 + return Compile(cx, obj, options, ascii, length);
5333 5282 }
5334 5283
5335 5284 JS_PUBLIC_API(JSScript *)
5336   -JS_CompileScript(JSContext *cx, JSObject *objArg, const char *bytes, size_t length,
  5285 +JS_CompileScript(JSContext *cx, JSObject *objArg, const char *ascii, size_t length,
5337 5286 const char *filename, unsigned lineno)
5338 5287 {
5339 5288 RootedObject obj(cx, objArg);
5340 5289 CompileOptions options(cx);
5341 5290 options.setFileAndLine(filename, lineno);
5342 5291
5343   - return Compile(cx, obj, options, bytes, length);
  5292 + return Compile(cx, obj, options, ascii, length);
5344 5293 }
5345 5294
5346 5295 JS_PUBLIC_API(JSBool)
5347   -JS_BufferIsCompilableUnit(JSContext *cx, JSBool bytes_are_utf8, JSObject *objArg, const char *bytes, size_t length)
  5296 +JS_BufferIsCompilableUnit(JSContext *cx, JSObject *objArg, const char *utf8, size_t length)
5348 5297 {
5349 5298 RootedObject obj(cx, objArg);
5350   - jschar *chars;
5351 5299 JSBool result;
5352 5300 JSExceptionState *exnState;
5353 5301 JSErrorReporter older;
@@ -5355,10 +5303,7 @@ JS_BufferIsCompilableUnit(JSContext *cx, JSBool bytes_are_utf8, JSObject *objArg
5355 5303 AssertHeapIsIdle(cx);
5356 5304 CHECK_REQUEST(cx);
5357 5305 assertSameCompartment(cx, obj);
5358   - if (bytes_are_utf8)
5359   - chars = InflateString(cx, bytes, &length, CESU8Encoding);
5360   - else
5361   - chars = InflateString(cx, bytes, &length);
  5306 + jschar *chars = InflateUTF8String(cx, utf8, &length);
5362 5307 if (!chars)
5363 5308 return JS_TRUE;
5364 5309
@@ -5416,20 +5361,6 @@ JS_CompileUTF8FileHandleForPrincipals(JSContext *cx, JSObject *objArg, const cha
5416 5361 }
5417 5362
5418 5363 JS_PUBLIC_API(JSScript *)
5419   -JS_CompileUTF8FileHandleForPrincipalsVersion(JSContext *cx, JSObject *objArg, const char *filename,
5420   - FILE *file, JSPrincipals *principals, JSVersion version)
5421   -{
5422   - RootedObject obj(cx, objArg);
5423   - CompileOptions options(cx);
5424   - options.setUTF8(true)
5425   - .setFileAndLine(filename, 1)
5426   - .setPrincipals(principals)
5427   - .setVersion(version);
5428   -
5429   - return Compile(cx, obj, options, file);
5430   -}
5431   -
5432   -JS_PUBLIC_API(JSScript *)
5433 5364 JS_CompileUTF8FileHandle(JSContext *cx, JSObject *objArg, const char *filename, FILE *file)
5434 5365 {
5435 5366 RootedObject obj(cx, objArg);
@@ -5504,7 +5435,7 @@ JS::CompileFunction(JSContext *cx, HandleObject obj, CompileOptions options,
5504 5435 {
5505 5436 jschar *chars;
5506 5437 if (options.utf8)
5507   - chars = InflateString(cx, bytes, &length, CESU8Encoding);
  5438 + chars = InflateUTF8String(cx, bytes, &length);
5508 5439 else
5509 5440 chars = InflateString(cx, bytes, &length);
5510 5441 if (!chars)
@@ -5516,39 +5447,6 @@ JS::CompileFunction(JSContext *cx, HandleObject obj, CompileOptions options,
5516 5447 }
5517 5448
5518 5449 JS_PUBLIC_API(JSFunction *)
5519   -JS_CompileUCFunctionForPrincipalsVersion(JSContext *cx, JSObject *obj_,
5520   - JSPrincipals *principals, const char *name,
5521   - unsigned nargs, const char **argnames,
5522   - const jschar *chars, size_t length,
5523   - const char *filename, unsigned lineno,
5524   - JSVersion version)
5525   -{
5526   - RootedObject obj(cx, obj_);
5527   -
5528   - CompileOptions options(cx);
5529   - options.setPrincipals(principals)
5530   - .setFileAndLine(filename, lineno)
5531   - .setVersion(version);
5532   -
5533   - return CompileFunction(cx, obj, options, name, nargs, argnames, chars, length);
5534   -}
5535   -
5536   -JS_PUBLIC_API(JSFunction *)
5537   -JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *objArg,
5538   - JSPrincipals *principals, const char *name,
5539   - unsigned nargs, const char **argnames,
5540   - const jschar *chars, size_t length,
5541   - const char *filename, unsigned lineno)
5542   -{
5543   - RootedObject obj(cx, objArg);
5544   - CompileOptions options(cx);
5545   - options.setPrincipals(principals)
5546   - .setFileAndLine(filename, lineno);
5547   -
5548   - return CompileFunction(cx, obj, options, name, nargs, argnames, chars, length);
5549   -}
5550   -
5551   -JS_PUBLIC_API(JSFunction *)
5552 5450 JS_CompileUCFunction(JSContext *cx, JSObject *objArg, const char *name,
5553 5451 unsigned nargs, const char **argnames,
5554 5452 const jschar *chars, size_t length,
@@ -5565,7 +5463,7 @@ JS_PUBLIC_API(JSFunction *)
5565 5463 JS_CompileFunctionForPrincipals(JSContext *cx, JSObject *objArg,
5566 5464 JSPrincipals *principals, const char *name,
5567 5465 unsigned nargs, const char **argnames,
5568   - const char *bytes, size_t length,
  5466 + const char *ascii, size_t length,
5569 5467 const char *filename, unsigned lineno)
5570 5468 {
5571 5469 RootedObject obj(cx, objArg);
@@ -5573,20 +5471,20 @@ JS_CompileFunctionForPrincipals(JSContext *cx, JSObject *objArg,
5573 5471 options.setPrincipals(principals)
5574 5472 .setFileAndLine(filename, lineno);
5575 5473
5576   - return CompileFunction(cx, obj, options, name, nargs, argnames, bytes, length);
  5474 + return CompileFunction(cx, obj, options, name, nargs, argnames, ascii, length);
5577 5475 }
5578 5476
5579 5477 JS_PUBLIC_API(JSFunction *)
5580 5478 JS_CompileFunction(JSContext *cx, JSObject *objArg, const char *name,
5581 5479 unsigned nargs, const char **argnames,
5582   - const char *bytes, size_t length,
  5480 + const char *ascii, size_t length,
5583 5481 const char *filename, unsigned lineno)
5584 5482 {
5585 5483 RootedObject obj(cx, objArg);
5586 5484 CompileOptions options(cx);
5587 5485 options.setFileAndLine(filename, lineno);
5588 5486
5589   - return CompileFunction(cx, obj, options, name, nargs, argnames, bytes, length);
  5487 + return CompileFunction(cx, obj, options, name, nargs, argnames, ascii, length);
5590 5488 }
5591 5489
5592 5490 JS_PUBLIC_API(JSString *)
@@ -5703,7 +5601,7 @@ JS::Evaluate(JSContext *cx, HandleObject obj, CompileOptions options,
5703 5601 {
5704 5602 jschar *chars;
5705 5603 if (options.utf8)
5706   - chars = InflateString(cx, bytes, &length, CESU8Encoding);
  5604 + chars = InflateUTF8String(cx, bytes, &length);
5707 5605 else
5708 5606 chars = InflateString(cx, bytes, &length);
5709 5607 if (!chars)
@@ -6283,26 +6181,6 @@ JS_UndependString(JSContext *cx, JSString *str)
6283 6181 }
6284 6182
6285 6183 JS_PUBLIC_API(JSBool)
6286   -JS_EncodeCharacters(JSContext *cx, const jschar *src, size_t srclen, char *dst, size_t *dstlenp)
6287   -{
6288   - AssertHeapIsIdle(cx);
6289   - CHECK_REQUEST(cx);
6290   -
6291   - size_t n;
6292   - if (!dst) {
6293   - n = GetDeflatedStringLength(cx, src, srclen);
6294   - if (n == (size_t)-1) {
6295   - *dstlenp = 0;
6296   - return JS_FALSE;
6297   - }
6298   - *dstlenp = n;
6299   - return JS_TRUE;
6300   - }
6301   -
6302   - return DeflateStringToBuffer(cx, src, srclen, dst, dstlenp);
6303   -}
6304   -
6305   -JS_PUBLIC_API(JSBool)
6306 6184 JS_DecodeBytes(JSContext *cx, const char *src, size_t srclen, jschar *dst, size_t *dstlenp)
6307 6185 {
6308 6186 AssertHeapIsIdle(cx);
@@ -6368,11 +6246,7 @@ JS_EncodeStringToBuffer(JSString *str, char *buffer, size_t length)
6368 6246 size_t necessaryLength = GetDeflatedStringLength(NULL, chars, str->length());
6369 6247 if (necessaryLength == size_t(-1))
6370 6248 return size_t(-1);
6371   - if (writtenLength != length) {
6372   - /* Make sure that the buffer contains only valid UTF-8 sequences. */
6373   - JS_ASSERT(js_CStringsAreUTF8);
6374   - PodZero(buffer + writtenLength, length - writtenLength);
6375   - }
  6249 + JS_ASSERT(writtenLength == length); // C strings are NOT encoded.
6376 6250 return necessaryLength;
6377 6251 }
6378 6252
@@ -6639,31 +6513,6 @@ JS_WriteBytes(JSStructuredCloneWriter *w, const void *p, size_t len)
6639 6513 return w->output().writeBytes(p, len);
6640 6514 }
6641 6515
6642   -/*
6643   - * The following determines whether C Strings are to be treated as UTF-8
6644   - * or ISO-8859-1. For correct operation, it must be set prior to the
6645   - * first call to JS_NewRuntime.
6646   - */
6647   -#ifndef JS_C_STRINGS_ARE_UTF8
6648   -JSBool js_CStringsAreUTF8 = JS_FALSE;
6649   -#endif
6650   -
6651   -JS_PUBLIC_API(JSBool)
6652   -JS_CStringsAreUTF8()
6653   -{
6654   - return js_CStringsAreUTF8;
6655   -}
6656   -
6657   -JS_PUBLIC_API(void)
6658   -JS_SetCStringsAreUTF8()
6659   -{
6660   - JS_ASSERT(!js_NewRuntimeWasCalled);
6661   -
6662   -#ifndef JS_C_STRINGS_ARE_UTF8
6663   - js_CStringsAreUTF8 = JS_TRUE;
6664   -#endif
6665   -}
6666   -
6667 6516 /************************************************************************/
6668 6517
6669 6518 JS_PUBLIC_API(void)
99 js/src/jsapi.h
@@ -1974,7 +1974,7 @@ typedef enum JSExnType {
1974 1974 } JSExnType;
1975 1975
1976 1976 typedef struct JSErrorFormatString {
1977   - /* The error format string (UTF-8 if js_CStringsAreUTF8). */
  1977 + /* The error format string in ASCII. */
1978 1978 const char *format;
1979 1979
1980 1980 /* The number of arguments to expand in the formatted error message. */
@@ -4948,28 +4948,20 @@ JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSRawObject parent);
4948 4948 * the compiler.
4949 4949 */
4950 4950 extern JS_PUBLIC_API(JSBool)
4951   -JS_BufferIsCompilableUnit(JSContext *cx, JSBool bytes_are_utf8,
4952   - JSObject *obj, const char *bytes, size_t length);
  4951 +JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj, const char *utf8, size_t length);
4953 4952
4954 4953 extern JS_PUBLIC_API(JSScript *)
4955 4954 JS_CompileScript(JSContext *cx, JSObject *obj,
4956   - const char *bytes, size_t length,
  4955 + const char *ascii, size_t length,
4957 4956 const char *filename, unsigned lineno);
4958 4957
4959 4958 extern JS_PUBLIC_API(JSScript *)
4960 4959 JS_CompileScriptForPrincipals(JSContext *cx, JSObject *obj,
4961 4960 JSPrincipals *principals,
4962   - const char *bytes, size_t length,
  4961 + const char *ascii, size_t length,
4963 4962 const char *filename, unsigned lineno);
4964 4963
4965 4964 extern JS_PUBLIC_API(JSScript *)
4966   -JS_CompileScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
4967   - JSPrincipals *principals,
4968   - const char *bytes, size_t length,
4969   - const char *filename, unsigned lineno,
4970   - JSVersion version);
4971   -
4972   -extern JS_PUBLIC_API(JSScript *)
4973 4965 JS_CompileUCScript(JSContext *cx, JSObject *obj,
4974 4966 const jschar *chars, size_t length,
4975 4967 const char *filename, unsigned lineno);
@@ -4981,24 +4973,6 @@ JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj,
4981 4973 const char *filename, unsigned lineno);
4982 4974
4983 4975 extern JS_PUBLIC_API(JSScript *)
4984   -JS_CompileUCScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
4985   - JSPrincipals *principals,
4986   - const jschar *chars, size_t length,
4987   - const char *filename, unsigned lineno,
4988   - JSVersion version);
4989   -/*
4990   - * If originPrincipals is null, then the value of principals is used as origin
4991   - * principals for the compiled script.
4992   - */
4993   -extern JS_PUBLIC_API(JSScript *)
4994   -JS_CompileUCScriptForPrincipalsVersionOrigin(JSContext *cx, JSObject *obj,
4995   - JSPrincipals *principals,
4996   - JSPrincipals *originPrincipals,
4997   - const jschar *chars, size_t length,
4998   - const char *filename, unsigned lineno,
4999   - JSVersion version);
5000   -
5001   -extern JS_PUBLIC_API(JSScript *)
5002 4976 JS_CompileUTF8File(JSContext *cx, JSObject *obj, const char *filename);
5003 4977
5004 4978 extern JS_PUBLIC_API(JSScript *)
@@ -5010,12 +4984,6 @@ JS_CompileUTF8FileHandleForPrincipals(JSContext *cx, JSObject *obj,
5010 4984 const char *filename, FILE *fh,
5011 4985 JSPrincipals *principals);
5012 4986
5013   -extern JS_PUBLIC_API(JSScript *)
5014   -JS_CompileUTF8FileHandleForPrincipalsVersion(JSContext *cx, JSObject *obj,
5015   - const char *filename, FILE *fh,
5016   - JSPrincipals *principals,
5017   - JSVersion version);
5018   -
5019 4987 extern JS_PUBLIC_API(JSObject *)
5020 4988 JS_GetGlobalFromScript(JSScript *script);
5021 4989
@@ -5038,21 +5006,6 @@ JS_CompileUCFunction(JSContext *cx, JSObject *obj, const char *name,
5038 5006 const jschar *chars, size_t length,
5039 5007 const char *filename, unsigned lineno);
5040 5008
5041   -extern JS_PUBLIC_API(JSFunction *)
5042   -JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj,
5043   - JSPrincipals *principals, const char *name,
5044   - unsigned nargs, const char **argnames,
5045   - const jschar *chars, size_t length,
5046   - const char *filename, unsigned lineno);
5047   -
5048   -extern JS_PUBLIC_API(JSFunction *)
5049   -JS_CompileUCFunctionForPrincipalsVersion(JSContext *cx, JSObject *obj,
5050   - JSPrincipals *principals, const char *name,
5051   - unsigned nargs, const char **argnames,
5052   - const jschar *chars, size_t length,
5053   - const char *filename, unsigned lineno,
5054   - JSVersion version);
5055   -
5056 5009 #ifdef __cplusplus
5057 5010 JS_END_EXTERN_C
5058 5011
@@ -5537,48 +5490,19 @@ extern JS_PUBLIC_API(const jschar *)
5537 5490 JS_UndependString(JSContext *cx, JSString *str);
5538 5491
5539 5492 /*
5540   - * Return JS_TRUE if C (char []) strings passed via the API and internally
5541   - * are UTF-8.
5542   - */
5543   -JS_PUBLIC_API(JSBool)
5544   -JS_CStringsAreUTF8(void);
5545   -
5546   -/*
5547   - * Update the value to be returned by JS_CStringsAreUTF8(). Once set, it
5548   - * can never be changed. This API must be called before the first call to
5549   - * JS_NewRuntime.
5550   - */
5551   -JS_PUBLIC_API(void)
5552   -JS_SetCStringsAreUTF8(void);
5553   -
5554   -/*
5555   - * Character encoding support.
5556   - *
5557   - * For both JS_EncodeCharacters and JS_DecodeBytes, set *dstlenp to the size
5558   - * of the destination buffer before the call; on return, *dstlenp contains the
5559   - * number of bytes (JS_EncodeCharacters) or jschars (JS_DecodeBytes) actually
5560   - * stored. To determine the necessary destination buffer size, make a sizing
5561   - * call that passes NULL for dst.
  5493 + * For JS_DecodeBytes, set *dstlenp to the size of the destination buffer before
  5494 + * the call; on return, *dstlenp contains the number of jschars actually stored.
  5495 + * To determine the necessary destination buffer size, make a sizing call that
  5496 + * passes NULL for dst.
5562 5497 *
5563 5498 * On errors, the functions report the error. In that case, *dstlenp contains
5564 5499 * the number of characters or bytes transferred so far. If cx is NULL, no
5565 5500 * error is reported on failure, and the functions simply return JS_FALSE.
5566 5501 *
5567   - * NB: Neither function stores an additional zero byte or jschar after the
  5502 + * NB: This function does not store an additional zero byte or jschar after the
5568 5503 * transcoded string.
5569   - *
5570   - * If JS_CStringsAreUTF8() is true then JS_EncodeCharacters encodes to
5571   - * UTF-8, and JS_DecodeBytes decodes from UTF-8, which may create additional
5572   - * errors if the character sequence is malformed. If UTF-8 support is
5573   - * disabled, the functions deflate and inflate, respectively.
5574   - *
5575   - * JS_DecodeUTF8() always behaves the same independently of JS_CStringsAreUTF8().
5576 5504 */
5577 5505 JS_PUBLIC_API(JSBool)
5578   -JS_EncodeCharacters(JSContext *cx, const jschar *src, size_t srclen, char *dst,
5579   - size_t *dstlenp);
5580   -
5581   -JS_PUBLIC_API(JSBool)
5582 5506 JS_DecodeBytes(JSContext *cx, const char *src, size_t srclen, jschar *dst,
5583 5507 size_t *dstlenp);
5584 5508
@@ -5608,11 +5532,6 @@ JS_GetStringEncodingLength(JSContext *cx, JSString *str);
5608 5532 * of bytes that are necessary to encode the string. If that exceeds the
5609 5533 * length parameter, the string will be cut and only length bytes will be
5610 5534 * written into the buffer.
5611   - *
5612   - * If JS_CStringsAreUTF8() is true, the string does not fit into the buffer
5613   - * and the the first length bytes ends in the middle of utf-8 encoding for
5614   - * some character, then such partial utf-8 encoding is replaced by zero bytes.
5615   - * This way the result always represents the valid UTF-8 sequence.
5616 5535 */
5617 5536 JS_PUBLIC_API(size_t)
5618 5537 JS_EncodeStringToBuffer(JSString *str, char *buffer, size_t length);
9 js/src/jsatom.cpp
@@ -319,7 +319,7 @@ js::AtomizeString(JSContext *cx, JSString *str, InternBehavior ib)
319 319 }
320 320
321 321 JSAtom *
322   -js::Atomize(JSContext *cx, const char *bytes, size_t length, InternBehavior ib, FlationCoding fc)
  322 +js::Atomize(JSContext *cx, const char *bytes, size_t length, InternBehavior ib)
323 323 {
324 324 CHECK_REQUEST(cx);
325 325
@@ -340,15 +340,12 @@ js::Atomize(JSContext *cx, const char *bytes, size_t length, InternBehavior ib,
340 340 const jschar *chars;
341 341 OwnCharsBehavior ocb = CopyChars;
342 342 if (length < ATOMIZE_BUF_MAX) {
343   - if (fc == CESU8Encoding)
344   - InflateUTF8StringToBuffer(cx, bytes, length, inflated, &inflatedLength, fc);
345   - else
346   - InflateStringToBuffer(cx, bytes, length, inflated, &inflatedLength);
  343 + InflateStringToBuffer(cx, bytes, length, inflated, &inflatedLength);
347 344 inflated[inflatedLength] = 0;
348 345 chars = inflated;
349 346 } else {
350 347 inflatedLength = length;
351   - chars = InflateString(cx, bytes, &inflatedLength, fc);
  348 + chars = InflateString(cx, bytes, &inflatedLength);
352 349 if (!chars)
353 350 return NULL;
354 351 ocb = TakeCharOwnership;
26 js/src/jsatom.h
@@ -119,29 +119,6 @@ struct AtomHasher
119 119
120 120 typedef HashSet<AtomStateEntry, AtomHasher, SystemAllocPolicy> AtomSet;
121 121
122   -/*
123   - * On encodings:
124   - *
125   - * - Some string functions have an optional FlationCoding argument that allow
126   - * the caller to force CESU-8 encoding handling.
127   - * - Functions that don't take a FlationCoding base their NormalEncoding
128   - * behavior on the js_CStringsAreUTF8 value. NormalEncoding is either raw
129   - * (simple zero-extension) or UTF-8 depending on js_CStringsAreUTF8.
130   - * - Functions that explicitly state their encoding do not use the
131   - * js_CStringsAreUTF8 value.
132   - *
133   - * CESU-8 (Compatibility Encoding Scheme for UTF-16: 8-bit) is a variant of
134   - * UTF-8 that allows us to store any wide character string as a narrow
135   - * character string. For strings containing mostly ascii, it saves space.
136   - * http://www.unicode.org/reports/tr26/
137   - */
138   -
139   -enum FlationCoding
140   -{
141   - NormalEncoding,
142   - CESU8Encoding
143   -};
144   -
145 122 class PropertyName;
146 123
147 124 } /* namespace js */
@@ -246,8 +223,7 @@ enum InternBehavior
246 223
247 224 extern JSAtom *
248 225 Atomize(JSContext *cx, const char *bytes, size_t length,
249   - js::InternBehavior ib = js::DoNotInternAtom,
250   - js::FlationCoding fc = js::NormalEncoding);
  226 + js::InternBehavior ib = js::DoNotInternAtom);
251 227
252 228 extern JSAtom *
253 229 AtomizeChars(JSContext *cx, const jschar *chars, size_t length,
13 js/src/jsprf.cpp
@@ -668,8 +668,6 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
668 668 struct NumArgState nasArray[ NAS_DEFAULT_NUM ];
669 669 char pattern[20];
670 670 const char *dolPt = NULL; /* in "%4$.2f", dolPt will poiont to . */
671   - uint8_t utf8buf[6];
672   - int utf8len;
673 671
674 672 /*
675 673 ** build an argument array, IF the fmt is numbered argument
@@ -906,13 +904,6 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
906 904 }
907 905 switch (type) {
908 906 case TYPE_INT16:
909   - /* Treat %hc as %c unless js_CStringsAreUTF8. */
910   - if (js_CStringsAreUTF8) {
911   - u.wch = va_arg(ap, int);
912   - utf8len = js_OneUcs4ToUtf8Char (utf8buf, u.wch);
913   - rv = (*ss->stuff)(ss, (char *)utf8buf, utf8len);
914   - break;
915   - }
916 907 case TYPE_INTN:
917 908 u.ch = va_arg(ap, int);
918 909 rv = (*ss->stuff)(ss, &u.ch, 1);
@@ -957,10 +948,6 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
957 948
958 949 case 's':
959 950 if(type == TYPE_INT16) {
960   - /*
961   - * This would do a simple string/byte conversion
962   - * unless js_CStringsAreUTF8.
963   - */
964 951 u.ws = va_arg(ap, const jschar*);
965 952 rv = cvt_ws(ss, u.ws, width, prec, flags);
966 953 } else {
5 js/src/jsprf.h
@@ -16,10 +16,9 @@
16 16 ** %hd, %hu, %hx, %hX, %ho - 16-bit versions of above
17 17 ** %ld, %lu, %lx, %lX, %lo - 32-bit versions of above
18 18 ** %lld, %llu, %llx, %llX, %llo - 64 bit versions of above
19   -** %s - string
20   -** %hs - 16-bit version of above (only available if js_CStringsAreUTF8)
  19 +** %s - ascii string
  20 +** %hs - ucs2 string
21 21 ** %c - character
22   -** %hc - 16-bit version of above (only available if js_CStringsAreUTF8)
23 22 ** %p - pointer (deals with machine dependent pointer size)
24 23 ** %f - float
25 24 ** %g - float
10 js/src/jsprvtd.h
@@ -379,16 +379,6 @@ typedef JSObject *
379 379 typedef JSObject *
380 380 (* JSIteratorOp)(JSContext *cx, JSHandleObject obj, JSBool keysonly);
381 381
382   -/*
383   - * The following determines whether JS_EncodeCharacters and JS_DecodeBytes
384   - * treat char[] as utf-8 or simply as bytes that need to be inflated/deflated.
385   - */
386   -#ifdef JS_C_STRINGS_ARE_UTF8
387   -# define js_CStringsAreUTF8 JS_TRUE
388   -#else
389   -extern JSBool js_CStringsAreUTF8;
390   -#endif
391   -
392 382 JS_END_EXTERN_C
393 383
394 384 #endif /* jsprvtd_h___ */
271 js/src/jsstr.cpp
@@ -3297,23 +3297,11 @@ NewShortString(JSContext *cx, const char *chars, size_t length)
3297 3297 if (!str)
3298 3298 return NULL;
3299 3299
3300   - jschar *storage = str->init(length);
3301   - if (js_CStringsAreUTF8) {
3302   -#ifdef DEBUG
3303   - size_t oldLength = length;
3304   -#endif
3305   - if (!InflateUTF8StringToBuffer(cx, chars, length, storage, &length))
3306   - return NULL;
3307   - JS_ASSERT(length <= oldLength);
3308   - storage[length] = 0;
3309   - str->resetLength(length);
3310   - } else {
3311   - size_t n = length;
3312   - jschar *p = storage;
3313   - while (n--)
3314   - *p++ = (unsigned char)*chars++;
3315   - *p = 0;
3316   - }
  3300 + size_t n = length;
  3301 + jschar *p = str->init(length);
  3302 + while (n--)
  3303 + *p++ = (unsigned char)*chars++;
  3304 + *p = 0;
3317 3305 Probes::createString(cx, str, length);
3318 3306 return str;
3319 3307 }
@@ -3615,7 +3603,34 @@ js_strchr_limit(const jschar *s, jschar c, const jschar *limit)
3615 3603 namespace js {
3616 3604
3617 3605 jschar *
3618   -InflateString(JSContext *cx, const char *bytes, size_t *lengthp, FlationCoding fc)
  3606 +InflateString(JSContext *cx, const char *bytes, size_t *lengthp)
  3607 +{
  3608 + AssertCanGC();
  3609 + size_t nchars;
  3610 + jschar *chars;
  3611 + size_t nbytes = *lengthp;
  3612 +
  3613 + nchars = nbytes;
  3614 + chars = cx->pod_malloc<jschar>(nchars + 1);
  3615 + if (!chars)
  3616 + goto bad;
  3617 + for (size_t i = 0; i < nchars; i++)
  3618 + chars[i] = (unsigned char) bytes[i];
  3619 + *lengthp = nchars;
  3620 + chars[nchars] = 0;
  3621 + return chars;
  3622 +
  3623 + bad:
  3624 + /*
  3625 + * For compatibility with callers of JS_DecodeBytes we must zero lengthp
  3626 + * on errors.
  3627 + */
  3628 + *lengthp = 0;
  3629 + return NULL;
  3630 +}
  3631 +
  3632 +jschar *
  3633 +InflateUTF8String(JSContext *cx, const char *bytes, size_t *lengthp)
3619 3634 {
3620 3635 AssertCanGC();
3621 3636 size_t nchars;
@@ -3625,21 +3640,12 @@ InflateString(JSContext *cx, const char *bytes, size_t *lengthp, FlationCoding f
3625 3640 // Malformed UTF8 chars could trigger errors and hence GC
3626 3641 MaybeCheckStackRoots(cx);
3627 3642
3628   - if (js_CStringsAreUTF8 || fc == CESU8Encoding) {
3629   - if (!InflateUTF8StringToBuffer(cx, bytes, nbytes, NULL, &nchars, fc))
3630   - goto bad;
3631   - chars = cx->pod_malloc<jschar>(nchars + 1);
3632   - if (!chars)
3633   - goto bad;
3634   - JS_ALWAYS_TRUE(InflateUTF8StringToBuffer(cx, bytes, nbytes, chars, &nchars, fc));
3635   - } else {
3636   - nchars = nbytes;
3637   - chars = cx->pod_malloc<jschar>(nchars + 1);
3638   - if (!chars)
3639   - goto bad;
3640   - for (size_t i = 0; i < nchars; i++)
3641   - chars[i] = (unsigned char) bytes[i];
3642   - }
  3643 + if (!InflateUTF8StringToBuffer(cx, bytes, nbytes, NULL, &nchars))
  3644 + goto bad;
  3645 + chars = cx->pod_malloc<jschar>(nchars + 1);
  3646 + if (!chars)
  3647 + goto bad;
  3648 + JS_ALWAYS_TRUE(InflateUTF8StringToBuffer(cx, bytes, nbytes, chars, &nchars));
3643 3649 *lengthp = nchars;
3644 3650 chars[nchars] = 0;
3645 3651 return chars;
@@ -3657,27 +3663,17 @@ InflateString(JSContext *cx, const char *bytes, size_t *lengthp, FlationCoding f
3657 3663 * May be called with null cx.
3658 3664 */
3659 3665 char *
3660   -DeflateString(JSContext *cx, const jschar *chars, size_t nchars)
  3666 +DeflateString(JSContext *maybecx, const jschar *chars, size_t nchars)
3661 3667 {
3662   - size_t nbytes, i;
3663   - char *bytes;
3664   -
3665   - if (js_CStringsAreUTF8) {
3666   - nbytes = GetDeflatedStringLength(cx, chars, nchars);
3667   - if (nbytes == (size_t) -1)
3668   - return NULL;
3669   - bytes = (char *) (cx ? cx->malloc_(nbytes + 1) : js_malloc(nbytes + 1));
3670   - if (!bytes)
3671   - return NULL;
3672   - JS_ALWAYS_TRUE(DeflateStringToBuffer(cx, chars, nchars, bytes, &nbytes));
3673   - } else {
3674   - nbytes = nchars;
3675   - bytes = (char *) (cx ? cx->malloc_(nbytes + 1) : js_malloc(nbytes + 1));
3676   - if (!bytes)
3677   - return NULL;
3678   - for (i = 0; i < nbytes; i++)
3679   - bytes[i] = (char) chars[i];
3680   - }
  3668 + AutoAssertNoGC nogc;
  3669 + size_t nbytes = nchars;
  3670 + char *bytes = maybecx
  3671 + ? maybecx->pod_malloc<char>(nbytes + 1)
  3672 + : js_pod_malloc<char>(nbytes + 1);
  3673 + if (!bytes)
  3674 + return NULL;
  3675 + for (size_t i = 0; i < nbytes; i++)
  3676 + bytes[i] = (char) chars[i];
3681 3677 bytes[nbytes] = 0;
3682 3678 return bytes;
3683 3679 }
@@ -3685,172 +3681,46 @@ DeflateString(JSContext *cx, const jschar *chars, size_t nchars)
3685 3681 size_t
3686 3682 GetDeflatedStringLength(JSContext *cx, const jschar *chars, size_t nchars)
3687 3683 {
3688   - if (!js_CStringsAreUTF8)
3689   - return nchars;
3690   -
3691   - return GetDeflatedUTF8StringLength(cx, chars, nchars);
3692   -}
3693   -
3694   -/*
3695   - * May be called with null cx through public API, see below.
3696   - */
3697   -size_t
3698   -GetDeflatedUTF8StringLength(JSContext *cx, const jschar *chars,
3699   - size_t nchars, FlationCoding fc)
3700   -{
3701   - size_t nbytes;
3702   - const jschar *end;
3703   - unsigned c, c2;
3704   - char buffer[10];
3705   - bool useCESU8 = fc == CESU8Encoding;
3706   -
3707   - nbytes = nchars;
3708   - for (end = chars + nchars; chars != end; chars++) {
3709   - c = *chars;
3710   - if (c < 0x80)
3711   - continue;
3712   - if (0xD800 <= c && c <= 0xDFFF && !useCESU8) {
3713   - /* Surrogate pair. */
3714   - chars++;
3715   -
3716   - /* nbytes sets 1 length since this is surrogate pair. */
3717   - nbytes--;
3718   - if (c >= 0xDC00 || chars == end)
3719   - goto bad_surrogate;
3720   - c2 = *chars;
3721   - if (c2 < 0xDC00 || c2 > 0xDFFF)
3722   - goto bad_surrogate;
3723   - c = ((c - 0xD800) << 10) + (c2 - 0xDC00) + 0x10000;
3724   - }
3725   - c >>= 11;
3726   - nbytes++;
3727   - while (c) {
3728   - c >>= 5;
3729   - nbytes++;
3730   - }
3731   - }
3732   - return nbytes;
3733   -
3734   - bad_surrogate:
3735   - if (cx) {
3736   - JS_snprintf(buffer, 10, "0x%x", c);
3737   - JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR, js_GetErrorMessage,
3738   - NULL, JSMSG_BAD_SURROGATE_CHAR, buffer);
3739   - }
3740   - return (size_t) -1;
  3684 + return nchars;
3741 3685 }
3742 3686
3743 3687 bool
3744   -DeflateStringToBuffer(JSContext *cx, const jschar *src, size_t srclen,
  3688 +DeflateStringToBuffer(JSContext *maybecx, const jschar *src, size_t srclen,
3745 3689 char *dst, size_t *dstlenp)
3746 3690 {
3747   - size_t dstlen, i;
3748   -
3749   - dstlen = *dstlenp;
3750   - if (!js_CStringsAreUTF8) {
3751   - if (srclen > dstlen) {
3752   - for (i = 0; i < dstlen; i++)
3753   - dst[i] = (char) src[i];
3754   - if (cx) {
3755   - JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
3756   - JSMSG_BUFFER_TOO_SMALL);
3757   - }
3758   - return JS_FALSE;
3759   - }
3760   - for (i = 0; i < srclen; i++)
3761   - dst[i] = (char) src[i];
3762   - *dstlenp = srclen;
3763   - return JS_TRUE;
3764   - }
3765   -
3766   - return DeflateStringToUTF8Buffer(cx, src, srclen, dst, dstlenp);
3767   -}
3768   -
3769   -bool
3770   -DeflateStringToUTF8Buffer(JSContext *cx, const jschar *src, size_t srclen,
3771   - char *dst, size_t *dstlenp, FlationCoding fc)
3772   -{
3773   - size_t i, utf8Len;
3774   - jschar c, c2;
3775   - uint32_t v;
3776   - uint8_t utf8buf[6];
3777   -
3778   - bool useCESU8 = fc == CESU8Encoding;
3779 3691 size_t dstlen = *dstlenp;
3780   - size_t origDstlen = dstlen;
3781   -
3782   - while (srclen) {
3783   - c = *src++;
3784   - srclen--;
3785   - if ((c >= 0xDC00) && (c <= 0xDFFF) && !useCESU8)
3786   - goto badSurrogate;
3787   - if (c < 0xD800 || c > 0xDBFF || useCESU8) {
3788   - v = c;
3789   - } else {
3790   - if (srclen < 1)
3791   - goto badSurrogate;
3792   - c2 = *src;
3793   - if ((c2 < 0xDC00) || (c2 > 0xDFFF))
3794   - goto badSurrogate;
3795   - src++;
3796   - srclen--;
3797   - v = ((c - 0xD800) << 10) + (c2 - 0xDC00) + 0x10000;
3798   - }
3799   - if (v < 0x0080) {
3800   - /* no encoding necessary - performance hack */
3801   - if (dstlen == 0)
3802   - goto bufferTooSmall;
3803   - *dst++ = (char) v;
3804   - utf8Len = 1;
3805   - } else {
3806   - utf8Len = js_OneUcs4ToUtf8Char(utf8buf, v);
3807   - if (utf8Len > dstlen)
3808   - goto bufferTooSmall;
3809   - for (i = 0; i < utf8Len; i++)
3810   - *dst++ = (char) utf8buf[i];
  3692 + if (srclen > dstlen) {
  3693 + for (size_t i = 0; i < dstlen; i++)
  3694 + dst[i] = (char) src[i];
  3695 + if (maybecx) {
  3696 + JS_ReportErrorNumber(maybecx, js_GetErrorMessage, NULL,
  3697 + JSMSG_BUFFER_TOO_SMALL);
3811 3698 }
3812   - dstlen -= utf8Len;
  3699 + return JS_FALSE;
3813 3700 }
3814   - *dstlenp = (origDstlen - dstlen);
  3701 + for (size_t i = 0; i < srclen; i++)
  3702 + dst[i] = (char) src[i];
  3703 + *dstlenp = srclen;
3815 3704 return JS_TRUE;
3816   -
3817   -badSurrogate:
3818   - *dstlenp = (origDstlen - dstlen);
3819   - /* Delegate error reporting to the measurement function. */
3820   - if (cx)
3821   - GetDeflatedStringLength(cx, src - 1, srclen + 1);
3822   - return JS_FALSE;
3823   -
3824   -bufferTooSmall:
3825   - *dstlenp = (origDstlen - dstlen);
3826   - if (cx) {
3827   - JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
3828   - JSMSG_BUFFER_TOO_SMALL);
3829   - }
3830   - return JS_FALSE;
3831 3705 }
3832 3706
  3707 +
3833 3708 bool
3834   -InflateStringToBuffer(JSContext *cx, const char *src, size_t srclen,
  3709 +InflateStringToBuffer(JSContext *maybecx, const char *src, size_t srclen,
3835 3710 jschar *dst, size_t *dstlenp)
3836 3711 {
3837   - size_t dstlen, i;
3838   -
3839   - if (js_CStringsAreUTF8)
3840   - return InflateUTF8StringToBuffer(cx, src, srclen, dst, dstlenp);
3841   -
3842 3712 if (dst) {
3843   - dstlen = *dstlenp;
  3713 + size_t dstlen = *dstlenp;
3844 3714 if (srclen > dstlen) {
3845   - for (i = 0; i < dstlen; i++)
  3715 + for (size_t i = 0; i < dstlen; i++)
3846 3716 dst[i] = (unsigned char) src[i];
3847   - if (cx) {
3848   - JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
  3717 + if (maybecx) {
  3718 + JS_ReportErrorNumber(maybecx, js_GetErrorMessage, NULL,
3849 3719 JSMSG_BUFFER_TOO_SMALL);
3850 3720 }
3851 3721 return JS_FALSE;
3852 3722 }
3853   - for (i = 0; i < srclen; i++)
  3723 + for (size_t i = 0; i < srclen; i++)
3854 3724 dst[i] = (unsigned char) src[i];
3855 3725 }
3856 3726 *dstlenp = srclen;
@@ -3859,7 +3729,7 @@ InflateStringToBuffer(JSContext *cx, const char *src, size_t srclen,
3859 3729
3860 3730 bool
3861 3731 InflateUTF8StringToBuffer(JSContext *cx, const char *src, size_t srclen,
3862   - jschar *dst, size_t *dstlenp, FlationCoding fc)
  3732 + jschar *dst, size_t *dstlenp)
3863 3733 {
3864 3734 size_t dstlen, origDstlen, offset, j, n;
3865 3735 uint32_t v;
@@ -3867,7 +3737,6 @@ InflateUTF8StringToBuffer(JSContext *cx, const char *src, size_t srclen,
3867 3737 dstlen = dst ? *dstlenp : (size_t) -1;
3868 3738 origDstlen = dstlen;
3869 3739 offset = 0;
3870   - bool useCESU8 = fc == CESU8Encoding;
3871 3740
3872 3741 while (srclen) {
3873 3742 v = (uint8_t) *src;
@@ -3884,7 +3753,7 @@ InflateUTF8StringToBuffer(JSContext *cx, const char *src, size_t srclen,
3884 3753 goto badCharacter;
3885 3754 }
3886 3755 v = Utf8ToOneUcs4Char((uint8_t *)src, n);
3887   - if (v >= 0x10000 && !useCESU8) {
  3756 + if (v >= 0x10000) {
3888 3757 v -= 0x10000;
3889 3758 if (v > 0xFFFFF || dstlen < 2) {
3890 3759 *dstlenp = (origDstlen - dstlen);