/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* * *Date:09November2002 *SUMMARY:Testthatinterpretercanhandlestringliteralsexceeding64K *Seehttp://bugzilla.mozilla.org/show_bug.cgi?id=179068 * *Testthattheinterpretercanhandlestringliteralsexceeding64Klimit. *Forthatthescriptpassestoeval()"str='LONG_STRING_LITERAL';"where *LONG_STRING_LITERALisastringwith200Kchars. * *IgorBukanovexplainsthetechniqueusedbelow: * *>PhilipSchwartauwrote: *>... *>Hereistheheartofthetestcase: *> *>// Generate 200K long string *>varlong_str=duplicate(LONG_STR_SEED,N); *>varstr=""; *>eval("str='".concat(long_str,"';")); *>vartest_is_ok=(str.length==LONG_STR_SEED.length*N); *> *> *>Thetestcasecreatestwoidenticalstrings,|long_str|and|str|.It *>useseval()simplytoassignthevalueof|long_str|to|str|.Whyis *>itnecessarytohavethevariable|str|,then?Whynotjustcreate *>|long_str|andtestit?Wouldn'tthisbeenough: *> *>// Generate 200K long string *>varlong_str=duplicate(LONG_STR_SEED,N); *>vartest_is_ok=(long_str.length==LONG_STR_SEED.length*N); *> *>Ordowespecificallyneedtotesteval()toexercisetheinterpreter? * *Thereasonforevalistoteststringliteralslikein'astringliteral *with100000characters...',Rhinodealsfinewithstringsgeneratedat *runtimewherelengths>64K.Withoutevalitwouldbenecessarytohave *atestfileexcedding64KwhichisnotthatpoliteforCVSandthena *specialtreatmentforthecompiledmodeinRhinoshouldbeadded. * * *> *>Ifso,isitimportanttousetheconcat()methodintheassignment,as *>youhavedone:|eval("str='".concat(long_str,"';"))|,orcanwesimply *>do|eval("str=long_str;")|? * *Theconcatisareplacementforeval("str='"+long_str+"';"),butas *long_strishuge,thisleadstoconstructingfirstanewstringvia *"str='"+long_strandthenanotheronevia("str='"+long_str)+"';" *whichtakestimeunderJDK1.1onasomethinglikeStrongArm200MHz. *Callingconcatmakeslesscopies,thatiswhyitisusedinthe *duplicatefunctionandthisisfasterthendoingrecursionlikeinthe *testcasetotestthat64Kdifferentstringliteralscanbehandled. *
*/ //----------------------------------------------------------------------------- var UBound = 0; var BUGNUMBER = 179068; var summary = 'Test that interpreter can handle string literals exceeding 64K'; var status = ''; var statusitems = []; var actual = ''; var actualvalues = []; var expect= ''; var expectedvalues = []; var LONG_STR_SEED = "0123456789"; var N = 20 * 1024; var str = "";
// Generate 200K long string and assign it to |str| via eval() var long_str = duplicate(LONG_STR_SEED, N);
eval("str='".concat(long_str, "';"));
status = inSection(1);
actual = str.length == LONG_STR_SEED.length * N
expect = true;
addThis();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.