Changeset 254418 in webkit
- Timestamp:
- Jan 12, 2020 5:18:45 PM (4 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r254416 r254418 1 2020-01-12 Yusuke Suzuki <ysuzuki@apple.com> 2 3 [JSC] Consistently use "var" in builtin JS 4 https://bugs.webkit.org/show_bug.cgi?id=206157 5 6 Reviewed by Mark Lam. 7 8 let / const requires additional bytecode to make it Empty initialized for now. 9 For builtin JS, we would like to keep it as efficient and compact as we can 10 so we should use `var` consistently. 11 12 * builtins/ArrayPrototype.js: 13 (sort.stringComparator): 14 (sort.compactSparse): 15 (sort.compactSlow): 16 (sort.compact): 17 (sort.merge): 18 (sort.mergeSort): 19 (sort.bucketSort): 20 (sort.comparatorSort): 21 (sort.stringSort): 22 (sort): 23 (globalPrivate.concatSlowPath): 24 (concat): 25 * builtins/FunctionPrototype.js: 26 (call): 27 (overriddenName.string_appeared_here.symbolHasInstance): 28 * builtins/GlobalOperations.js: 29 (globalPrivate.copyDataProperties): 30 (globalPrivate.copyDataPropertiesNoExclusions): 31 * builtins/IteratorHelpers.js: 32 (performIteration): 33 * builtins/ModuleLoader.js: 34 (async loadModule): 35 (async loadAndEvaluateModule): 36 (async requestImportModule): 37 (dependencyKeysIfEvaluated): 38 * builtins/ObjectConstructor.js: 39 (fromEntries): 40 * builtins/PromisePrototype.js: 41 (finally): 42 (valueThunk): 43 (globalPrivate.getThenFinally): 44 (thrower): 45 (globalPrivate.getCatchFinally): 46 (const.valueThunk): Deleted. 47 (const.thrower): Deleted. 48 * builtins/RegExpPrototype.js: 49 (globalPrivate.advanceStringIndex): 50 (globalPrivate.regExpExec): 51 (globalPrivate.hasObservableSideEffectsForRegExpMatch): 52 (globalPrivate.matchSlow): 53 (overriddenName.string_appeared_here.match): 54 (overriddenName.string_appeared_here.matchAll): 55 (getSubstitution): 56 (overriddenName.string_appeared_here.replace): 57 (overriddenName.string_appeared_here.search): 58 (globalPrivate.hasObservableSideEffectsForRegExpSplit): 59 (overriddenName.string_appeared_here.split): 60 (intrinsic.RegExpTestIntrinsic.test): 61 * builtins/RegExpStringIteratorPrototype.js: 62 (next): 63 * builtins/StringPrototype.js: 64 (match): 65 (matchAll): 66 (globalPrivate.hasObservableSideEffectsForStringReplace): 67 (intrinsic.StringPrototypeReplaceIntrinsic.replace): 68 (globalPrivate.createHTML): 69 * builtins/TypedArrayConstructor.js: 70 (of): 71 (from): 72 * builtins/TypedArrayPrototype.js: 73 (globalPrivate.typedArraySpeciesConstructor): 74 (globalPrivate.typedArrayClampArgumentToStartOrEnd): 75 (fill): 76 (find): 77 (subarray): 78 1 79 2020-01-12 Yusuke Suzuki <ysuzuki@apple.com> 2 80 -
trunk/Source/JavaScriptCore/builtins/ArrayPrototype.js
r254252 r254418 318 318 function stringComparator(a, b) 319 319 { 320 letaString = a.string;321 letbString = b.string;322 323 letaLength = aString.length;324 letbLength = bString.length;325 letlength = min(aLength, bLength);326 327 for ( leti = 0; i < length; ++i) {328 letaCharCode = aString.@charCodeAt(i);329 letbCharCode = bString.@charCodeAt(i);320 var aString = a.string; 321 var bString = b.string; 322 323 var aLength = aString.length; 324 var bLength = bString.length; 325 var length = min(aLength, bLength); 326 327 for (var i = 0; i < length; ++i) { 328 var aCharCode = aString.@charCodeAt(i); 329 var bCharCode = bString.@charCodeAt(i); 330 330 331 331 if (aCharCode == bCharCode) … … 341 341 function compactSparse(array, dst, src, length) 342 342 { 343 letvalues = [ ];344 letseen = { };345 letvalueCount = 0;346 letundefinedCount = 0;343 var values = [ ]; 344 var seen = { }; 345 var valueCount = 0; 346 var undefinedCount = 0; 347 347 348 348 // Clean up after the in-progress non-sparse compaction that failed. 349 for ( leti = dst; i < src; ++i)349 for (var i = dst; i < src; ++i) 350 350 delete array[i]; 351 351 352 for ( letobject = array; object; object = @Object.@getPrototypeOf(object)) {353 letpropertyNames = @Object.@getOwnPropertyNames(object);354 for ( leti = 0; i < propertyNames.length; ++i) {355 letindex = propertyNames[i];352 for (var object = array; object; object = @Object.@getPrototypeOf(object)) { 353 var propertyNames = @Object.@getOwnPropertyNames(object); 354 for (var i = 0; i < propertyNames.length; ++i) { 355 var index = propertyNames[i]; 356 356 if (index < length) { // Exclude non-numeric properties and properties past length. 357 357 if (seen[index]) // Exclude duplicates. … … 359 359 seen[index] = 1; 360 360 361 letvalue = array[index];361 var value = array[index]; 362 362 delete array[index]; 363 363 … … 372 372 } 373 373 374 for ( leti = valueCount; i < valueCount + undefinedCount; ++i)374 for (var i = valueCount; i < valueCount + undefinedCount; ++i) 375 375 array[i] = @undefined; 376 376 … … 380 380 function compactSlow(array, length) 381 381 { 382 letholeCount = 0;383 384 letdst = 0;385 letsrc = 0;382 var holeCount = 0; 383 384 var dst = 0; 385 var src = 0; 386 386 for (; src < length; ++src) { 387 387 if (!(src in array)) { … … 392 392 } 393 393 394 letvalue = array[src];394 var value = array[src]; 395 395 if (value === @undefined) 396 396 continue; … … 399 399 } 400 400 401 letvalueCount = dst;402 letundefinedCount = length - valueCount - holeCount;403 404 for ( leti = valueCount; i < valueCount + undefinedCount; ++i)401 var valueCount = dst; 402 var undefinedCount = length - valueCount - holeCount; 403 404 for (var i = valueCount; i < valueCount + undefinedCount; ++i) 405 405 array[i] = @undefined; 406 406 407 for ( leti = valueCount + undefinedCount; i < length; ++i)407 for (var i = valueCount + undefinedCount; i < length; ++i) 408 408 delete array[i]; 409 409 … … 414 414 function compact(array, length) 415 415 { 416 for ( leti = 0; i < array.length; ++i) {416 for (var i = 0; i < array.length; ++i) { 417 417 if (array[i] === @undefined) 418 418 return compactSlow(array, length); … … 424 424 function merge(dst, src, srcIndex, srcEnd, width, comparator) 425 425 { 426 letleft = srcIndex;427 letleftEnd = min(left + width, srcEnd);428 letright = leftEnd;429 letrightEnd = min(right + width, srcEnd);430 431 for ( letdstIndex = left; dstIndex < rightEnd; ++dstIndex) {426 var left = srcIndex; 427 var leftEnd = min(left + width, srcEnd); 428 var right = leftEnd; 429 var rightEnd = min(right + width, srcEnd); 430 431 for (var dstIndex = left; dstIndex < rightEnd; ++dstIndex) { 432 432 if (right < rightEnd) { 433 433 if (left >= leftEnd) { … … 436 436 } 437 437 438 letcomparisonResult = comparator(src[right], src[left]);438 var comparisonResult = comparator(src[right], src[left]); 439 439 if ((typeof comparisonResult === "boolean" && !comparisonResult) || comparisonResult < 0) { 440 440 dst[dstIndex] = src[right++]; … … 450 450 function mergeSort(array, valueCount, comparator) 451 451 { 452 letbuffer = [ ];452 var buffer = [ ]; 453 453 buffer.length = valueCount; 454 454 455 letdst = buffer;456 letsrc = array;457 for ( letwidth = 1; width < valueCount; width *= 2) {458 for ( letsrcIndex = 0; srcIndex < valueCount; srcIndex += 2 * width)455 var dst = buffer; 456 var src = array; 457 for (var width = 1; width < valueCount; width *= 2) { 458 for (var srcIndex = 0; srcIndex < valueCount; srcIndex += 2 * width) 459 459 merge(dst, src, srcIndex, valueCount, width, comparator); 460 460 461 lettmp = src;461 var tmp = src; 462 462 src = dst; 463 463 dst = tmp; … … 465 465 466 466 if (src != array) { 467 for( leti = 0; i < valueCount; i++)467 for(var i = 0; i < valueCount; i++) 468 468 array[i] = src[i]; 469 469 } … … 474 474 if (bucket.length < 32 || depth > 32) { 475 475 mergeSort(bucket, bucket.length, stringComparator); 476 for ( leti = 0; i < bucket.length; ++i)476 for (var i = 0; i < bucket.length; ++i) 477 477 array[dst++] = bucket[i].value; 478 478 return dst; 479 479 } 480 480 481 letbuckets = [ ];482 for ( leti = 0; i < bucket.length; ++i) {483 letentry = bucket[i];484 letstring = entry.string;481 var buckets = [ ]; 482 for (var i = 0; i < bucket.length; ++i) { 483 var entry = bucket[i]; 484 var string = entry.string; 485 485 if (string.length == depth) { 486 486 array[dst++] = entry.value; … … 488 488 } 489 489 490 letc = string.@charCodeAt(depth);490 var c = string.@charCodeAt(depth); 491 491 if (!buckets[c]) 492 492 buckets[c] = [ ]; … … 494 494 } 495 495 496 for ( leti = 0; i < buckets.length; ++i) {496 for (var i = 0; i < buckets.length; ++i) { 497 497 if (!buckets[i]) 498 498 continue; … … 505 505 function comparatorSort(array, length, comparator) 506 506 { 507 letvalueCount = compact(array, length);507 var valueCount = compact(array, length); 508 508 mergeSort(array, valueCount, comparator); 509 509 } … … 511 511 function stringSort(array, length) 512 512 { 513 letvalueCount = compact(array, length);514 515 letstrings = @newArrayWithSize(valueCount);516 for ( leti = 0; i < valueCount; ++i)513 var valueCount = compact(array, length); 514 515 var strings = @newArrayWithSize(valueCount); 516 for (var i = 0; i < valueCount; ++i) 517 517 strings[i] = { string: @toString(array[i]), value: array[i] }; 518 518 … … 520 520 } 521 521 522 letsortFunction;522 var sortFunction; 523 523 if (typeof comparator == "function") 524 524 sortFunction = comparatorSort; … … 528 528 @throwTypeError("Array.prototype.sort requires the comparsion function be a function or undefined"); 529 529 530 letarray = @toObject(this, "Array.prototype.sort requires that |this| not be null or undefined");531 532 letlength = @toLength(array.length);530 var array = @toObject(this, "Array.prototype.sort requires that |this| not be null or undefined"); 531 532 var length = @toLength(array.length); 533 533 534 534 // For compatibility with Firefox and Chrome, do nothing observable … … 556 556 557 557 do { 558 letspreadable = @isObject(currentElement) && currentElement.@isConcatSpreadableSymbol;558 var spreadable = @isObject(currentElement) && currentElement.@isConcatSpreadableSymbol; 559 559 if ((spreadable === @undefined && @isArray(currentElement)) || spreadable) { 560 letlength = @toLength(currentElement.length);560 var length = @toLength(currentElement.length); 561 561 if (length + resultIndex > @MAX_ARRAY_INDEX) 562 562 @throwRangeError("Length exceeded the maximum array length"); … … 592 592 && (!@isObject(first) || (!@isProxyObject(first) && first.@isConcatSpreadableSymbol === @undefined))) { 593 593 594 letresult = @concatMemcpy(this, first);594 var result = @concatMemcpy(this, first); 595 595 if (result !== null) 596 596 return result; -
trunk/Source/JavaScriptCore/builtins/FunctionPrototype.js
r253867 r254418 28 28 "use strict"; 29 29 30 letargumentValues = [];30 var argumentValues = []; 31 31 // Start from 1 to ignore thisArgument 32 for ( leti = 1; i < arguments.length; i++)32 for (var i = 1; i < arguments.length; i++) 33 33 @putByValDirect(argumentValues, i-1, arguments[i]); 34 34 … … 54 54 return @hasInstanceBoundFunction(this, value); 55 55 56 lettarget = this.prototype;56 var target = this.prototype; 57 57 return @instanceOf(value, target); 58 58 } -
trunk/Source/JavaScriptCore/builtins/GlobalOperations.js
r242382 r254418 96 96 return target; 97 97 98 letfrom = @toObject(source);99 letkeys = @ownKeys(from);100 letkeysLength = keys.length;101 for ( leti = 0; i < keysLength; i++) {102 letnextKey = keys[i];98 var from = @toObject(source); 99 var keys = @ownKeys(from); 100 var keysLength = keys.length; 101 for (var i = 0; i < keysLength; i++) { 102 var nextKey = keys[i]; 103 103 if (!excludedSet.@has(nextKey)) { 104 104 if (@propertyIsEnumerable(from, nextKey)) { 105 letpropValue = from[nextKey];105 var propValue = from[nextKey]; 106 106 @defineEnumerableWritableConfigurableDataProperty(target, nextKey, propValue); 107 107 } … … 123 123 return target; 124 124 125 letfrom = @toObject(source);126 letkeys = @ownKeys(from);127 letkeysLength = keys.length;128 for ( leti = 0; i < keysLength; i++) {129 letnextKey = keys[i];125 var from = @toObject(source); 126 var keys = @ownKeys(from); 127 var keysLength = keys.length; 128 for (var i = 0; i < keysLength; i++) { 129 var nextKey = keys[i]; 130 130 if (@propertyIsEnumerable(from, nextKey)) { 131 letpropValue = from[nextKey];131 var propValue = from[nextKey]; 132 132 @defineEnumerableWritableConfigurableDataProperty(target, nextKey, propValue); 133 133 } -
trunk/Source/JavaScriptCore/builtins/IteratorHelpers.js
r222421 r254418 31 31 // https://tc39.github.io/ecma262/#sec-runtime-semantics-arrayaccumulation 32 32 33 letresult = [];33 var result = []; 34 34 35 letiterator = iterable.@iteratorSymbol();36 letnext = iterator.next;37 letitem;38 letindex = 0;35 var iterator = iterable.@iteratorSymbol(); 36 var next = iterator.next; 37 var item; 38 var index = 0; 39 39 while (true) { 40 40 item = next.@call(iterator); -
trunk/Source/JavaScriptCore/builtins/ModuleLoader.js
r249509 r254418 339 339 // Take the name and resolve it to the unique identifier for the resource location. 340 340 // For example, take the "jquery" and return the URL for the resource. 341 letkey = await this.resolve(moduleName, @undefined, fetcher);342 letentry = await this.requestSatisfy(this.ensureRegistered(key), parameters, fetcher, new @Set);341 var key = await this.resolve(moduleName, @undefined, fetcher); 342 var entry = await this.requestSatisfy(this.ensureRegistered(key), parameters, fetcher, new @Set); 343 343 return entry.key; 344 344 } … … 360 360 "use strict"; 361 361 362 letkey = await this.loadModule(moduleName, parameters, fetcher);362 var key = await this.loadModule(moduleName, parameters, fetcher); 363 363 return await this.linkAndEvaluateModule(key, fetcher); 364 364 } … … 368 368 "use strict"; 369 369 370 letentry = await this.requestSatisfy(this.ensureRegistered(key), parameters, fetcher, new @Set);370 var entry = await this.requestSatisfy(this.ensureRegistered(key), parameters, fetcher, new @Set); 371 371 this.linkAndEvaluateModule(entry.key, fetcher); 372 372 return this.getModuleNamespaceObject(entry.module); … … 377 377 "use strict"; 378 378 379 letentry = this.registry.@get(key);379 var entry = this.registry.@get(key); 380 380 if (!entry || !entry.evaluated) 381 381 return null; 382 382 383 letdependencies = entry.dependencies;384 letlength = dependencies.length;385 letresult = new @Array(length);386 for ( leti = 0; i < length; ++i)383 var dependencies = entry.dependencies; 384 var length = dependencies.length; 385 var result = new @Array(length); 386 for (var i = 0; i < length; ++i) 387 387 result[i] = dependencies[i].key; 388 388 -
trunk/Source/JavaScriptCore/builtins/ObjectConstructor.js
r241644 r254418 46 46 "use strict"; 47 47 48 letobject = {};48 var object = {}; 49 49 50 for ( letentry of iterable) {50 for (var entry of iterable) { 51 51 if (!@isObject(entry)) 52 52 @throwTypeError("Object.fromEntries requires the first iterable parameter yields objects"); 53 letkey = entry[0];54 letvalue = entry[1];53 var key = entry[0]; 54 var value = entry[1]; 55 55 @putByValDirect(object, key, value); 56 56 } -
trunk/Source/JavaScriptCore/builtins/PromisePrototype.js
r249509 r254418 80 80 @throwTypeError("|this| is not an object"); 81 81 82 constconstructor = @speciesConstructor(this, @Promise);82 var constructor = @speciesConstructor(this, @Promise); 83 83 84 84 @assert(@isConstructor(constructor)); 85 85 86 letthenFinally;87 letcatchFinally;86 var thenFinally; 87 var catchFinally; 88 88 89 89 if (typeof onFinally !== "function") { … … 106 106 { 107 107 @assert(typeof onFinally === "function"); 108 constresult = onFinally();108 var result = onFinally(); 109 109 110 110 @assert(@isConstructor(constructor)); 111 constresultCapability = @newPromiseCapability(constructor);111 var resultCapability = @newPromiseCapability(constructor); 112 112 113 113 resultCapability.@resolve.@call(@undefined, result); 114 114 115 constpromise = resultCapability.@promise;116 constvalueThunk = function () { return value; };115 var promise = resultCapability.@promise; 116 var valueThunk = function () { return value; }; 117 117 118 118 return promise.then(valueThunk); … … 128 128 { 129 129 @assert(typeof onFinally === "function"); 130 constresult = onFinally();130 var result = onFinally(); 131 131 132 132 @assert(@isConstructor(constructor)); 133 constresultCapability = @newPromiseCapability(constructor);133 var resultCapability = @newPromiseCapability(constructor); 134 134 135 135 resultCapability.@resolve.@call(@undefined, result); 136 136 137 constpromise = resultCapability.@promise;138 constthrower = function () { throw reason; };137 var promise = resultCapability.@promise; 138 var thrower = function () { throw reason; }; 139 139 140 140 return promise.then(thrower); -
trunk/Source/JavaScriptCore/builtins/RegExpPrototype.js
r254195 r254418 49 49 return index + 1; 50 50 51 letfirst = string.@charCodeAt(index);51 var first = string.@charCodeAt(index); 52 52 if (first < 0xD800 || first > 0xDBFF) 53 53 return index + 1; 54 54 55 letsecond = string.@charCodeAt(index + 1);55 var second = string.@charCodeAt(index + 1); 56 56 if (second < 0xDC00 || second > 0xDFFF) 57 57 return index + 1; … … 65 65 "use strict"; 66 66 67 letexec = regexp.exec;68 letbuiltinExec = @regExpBuiltinExec;67 var exec = regexp.exec; 68 var builtinExec = @regExpBuiltinExec; 69 69 if (exec !== builtinExec && typeof exec === "function") { 70 letresult = exec.@call(regexp, str);70 var result = exec.@call(regexp, str); 71 71 if (result !== null && !@isObject(result)) 72 72 @throwTypeError("The result of a RegExp exec must be null or an object"); … … 85 85 86 86 // This is accessed by the RegExpExec internal function. 87 letregexpExec = @tryGetById(regexp, "exec");87 var regexpExec = @tryGetById(regexp, "exec"); 88 88 if (regexpExec !== @regExpBuiltinExec) 89 89 return true; 90 90 91 letregexpGlobal = @tryGetById(regexp, "global");91 var regexpGlobal = @tryGetById(regexp, "global"); 92 92 if (regexpGlobal !== @regExpProtoGlobalGetter) 93 93 return true; 94 letregexpUnicode = @tryGetById(regexp, "unicode");94 var regexpUnicode = @tryGetById(regexp, "unicode"); 95 95 if (regexpUnicode !== @regExpProtoUnicodeGetter) 96 96 return true; … … 107 107 return @regExpExec(regexp, str); 108 108 109 letunicode = regexp.unicode;109 var unicode = regexp.unicode; 110 110 regexp.lastIndex = 0; 111 letresultList = [];111 var resultList = []; 112 112 113 113 // FIXME: It would be great to implement a solution similar to what we do in 114 114 // RegExpObject::matchGlobal(). It's not clear if this is possible, since this loop has 115 115 // effects. https://bugs.webkit.org/show_bug.cgi?id=158145 116 constmaximumReasonableMatchSize = 100000000;116 var maximumReasonableMatchSize = 100000000; 117 117 118 118 while (true) { 119 letresult = @regExpExec(regexp, str);119 var result = @regExpExec(regexp, str); 120 120 121 121 if (result === null) { … … 128 128 @throwOutOfMemoryError(); 129 129 130 letresultString = @toString(result[0]);130 var resultString = @toString(result[0]); 131 131 132 132 if (!resultString.length) … … 145 145 @throwTypeError("RegExp.prototype.@@match requires that |this| be an Object"); 146 146 147 letstr = @toString(strArg);147 var str = @toString(strArg); 148 148 149 149 // Check for observable side effects and call the fast path if there aren't any. … … 158 158 "use strict"; 159 159 160 letregExp = this;160 var regExp = this; 161 161 if (!@isObject(regExp)) 162 162 @throwTypeError("RegExp.prototype.@@matchAll requires |this| to be an Object"); 163 163 164 letstring = @toString(strArg);165 letMatcher = @speciesConstructor(regExp, @RegExp);166 167 letflags = @toString(regExp.flags);168 letmatcher = new Matcher(regExp, flags);164 var string = @toString(strArg); 165 var Matcher = @speciesConstructor(regExp, @RegExp); 166 167 var flags = @toString(regExp.flags); 168 var matcher = new Matcher(regExp, flags); 169 169 matcher.lastIndex = @toLength(regExp.lastIndex); 170 170 171 letglobal = @stringIncludesInternal.@call(flags, "g");172 letfullUnicode = @stringIncludesInternal.@call(flags, "u");171 var global = @stringIncludesInternal.@call(flags, "g"); 172 var fullUnicode = @stringIncludesInternal.@call(flags, "u"); 173 173 174 174 return new @RegExpStringIterator(matcher, string, global, fullUnicode); … … 184 184 "use strict"; 185 185 186 letmatchLength = matched.length;187 letstringLength = str.length;188 lettailPos = position + matchLength;189 letm = captures.length;190 letreplacementLength = replacement.length;191 letresult = "";192 letlastStart = 0;193 194 for ( letstart = 0; start = replacement.indexOf("$", lastStart), start !== -1; lastStart = start) {186 var matchLength = matched.length; 187 var stringLength = str.length; 188 var tailPos = position + matchLength; 189 var m = captures.length; 190 var replacementLength = replacement.length; 191 var result = ""; 192 var lastStart = 0; 193 194 for (var start = 0; start = replacement.indexOf("$", lastStart), start !== -1; lastStart = start) { 195 195 if (start - lastStart > 0) 196 196 result = result + replacement.substring(lastStart, start); 197 197 start++; 198 letch = replacement.charAt(start);198 var ch = replacement.charAt(start); 199 199 if (ch === "") 200 200 result = result + "$"; … … 222 222 case "<": 223 223 if (namedCaptures !== @undefined) { 224 letgroupNameStartIndex = start + 1;225 letgroupNameEndIndex = replacement.indexOf(">", groupNameStartIndex);224 var groupNameStartIndex = start + 1; 225 var groupNameEndIndex = replacement.indexOf(">", groupNameStartIndex); 226 226 if (groupNameEndIndex !== -1) { 227 letgroupName = replacement.substring(groupNameStartIndex, groupNameEndIndex);228 letcapture = namedCaptures[groupName];227 var groupName = replacement.substring(groupNameStartIndex, groupNameEndIndex); 228 var capture = namedCaptures[groupName]; 229 229 if (capture !== @undefined) 230 230 result = result + @toString(capture); … … 239 239 break; 240 240 default: 241 letchCode = ch.charCodeAt(0);241 var chCode = ch.charCodeAt(0); 242 242 if (chCode >= 0x30 && chCode <= 0x39) { 243 letoriginalStart = start - 1;243 var originalStart = start - 1; 244 244 start++; 245 245 246 letn = chCode - 0x30;246 var n = chCode - 0x30; 247 247 if (n > m) { 248 248 result = result + replacement.substring(originalStart, start); … … 251 251 252 252 if (start < replacementLength) { 253 letnextChCode = replacement.charCodeAt(start);253 var nextChCode = replacement.charCodeAt(start); 254 254 if (nextChCode >= 0x30 && nextChCode <= 0x39) { 255 letnn = 10 * n + nextChCode - 0x30;255 var nn = 10 * n + nextChCode - 0x30; 256 256 if (nn <= m) { 257 257 n = nn; … … 266 266 } 267 267 268 letcapture = captures[n - 1];268 var capture = captures[n - 1]; 269 269 if (capture !== @undefined) 270 270 result = result + capture; … … 282 282 @throwTypeError("RegExp.prototype.@@replace requires that |this| be an Object"); 283 283 284 letregexp = this;285 286 letstr = @toString(strArg);287 letstringLength = str.length;288 letfunctionalReplace = typeof replace === 'function';284 var regexp = this; 285 286 var str = @toString(strArg); 287 var stringLength = str.length; 288 var functionalReplace = typeof replace === 'function'; 289 289 290 290 if (!functionalReplace) 291 291 replace = @toString(replace); 292 292 293 letglobal = regexp.global;294 letunicode = false;293 var global = regexp.global; 294 var unicode = false; 295 295 296 296 if (global) { … … 299 299 } 300 300 301 letresultList = [];302 letresult;303 letdone = false;301 var resultList = []; 302 var result; 303 var done = false; 304 304 while (!done) { 305 305 result = @regExpExec(regexp, str); … … 312 312 done = true; 313 313 else { 314 letmatchStr = @toString(result[0]);314 var matchStr = @toString(result[0]); 315 315 316 316 if (!matchStr.length) … … 320 320 } 321 321 322 letaccumulatedResult = "";323 letnextSourcePosition = 0;324 letlastPosition = 0;325 326 for ( leti = 0, resultListLength = resultList.length; i < resultListLength; ++i) {327 letresult = resultList[i];328 letnCaptures = result.length - 1;322 var accumulatedResult = ""; 323 var nextSourcePosition = 0; 324 var lastPosition = 0; 325 326 for (var i = 0, resultListLength = resultList.length; i < resultListLength; ++i) { 327 var result = resultList[i]; 328 var nCaptures = result.length - 1; 329 329 if (nCaptures < 0) 330 330 nCaptures = 0; 331 letmatched = @toString(result[0]);332 letmatchLength = matched.length;333 letposition = result.index;331 var matched = @toString(result[0]); 332 var matchLength = matched.length; 333 var position = result.index; 334 334 position = (position > stringLength) ? stringLength : position; 335 335 position = (position < 0) ? 0 : position; 336 336 337 letcaptures = [];338 for ( letn = 1; n <= nCaptures; n++) {339 letcapN = result[n];337 var captures = []; 338 for (var n = 1; n <= nCaptures; n++) { 339 var capN = result[n]; 340 340 if (capN !== @undefined) 341 341 capN = @toString(capN); … … 343 343 } 344 344 345 letreplacement;346 letnamedCaptures = result.groups;345 var replacement; 346 var namedCaptures = result.groups; 347 347 348 348 if (functionalReplace) { 349 letreplacerArgs = [ matched ].concat(captures);349 var replacerArgs = [ matched ].concat(captures); 350 350 replacerArgs.@push(position); 351 351 replacerArgs.@push(str); … … 354 354 replacerArgs.@push(namedCaptures); 355 355 356 letreplValue = replace.@apply(@undefined, replacerArgs);356 var replValue = replace.@apply(@undefined, replacerArgs); 357 357 replacement = @toString(replValue); 358 358 } else { … … 382 382 "use strict"; 383 383 384 letregexp = this;384 var regexp = this; 385 385 386 386 // Check for observable side effects and call the fast path if there aren't any. … … 396 396 397 397 // 3. Let S be ? ToString(string). 398 letstr = @toString(strArg)398 var str = @toString(strArg) 399 399 400 400 // 4. Let previousLastIndex be ? Get(rx, "lastIndex"). 401 letpreviousLastIndex = regexp.lastIndex;401 var previousLastIndex = regexp.lastIndex; 402 402 403 403 // 5.If SameValue(previousLastIndex, 0) is false, then … … 408 408 409 409 // 6. Let result be ? RegExpExec(rx, S). 410 letresult = @regExpExec(regexp, str);410 var result = @regExpExec(regexp, str); 411 411 412 412 // 7. Let currentLastIndex be ? Get(rx, "lastIndex"). … … 434 434 435 435 // This is accessed by the RegExpExec internal function. 436 letregexpExec = @tryGetById(regexp, "exec");436 var regexpExec = @tryGetById(regexp, "exec"); 437 437 if (regexpExec !== @regExpBuiltinExec) 438 438 return true; 439 439 440 440 // This is accessed by step 5 below. 441 letregexpFlags = @tryGetById(regexp, "flags");441 var regexpFlags = @tryGetById(regexp, "flags"); 442 442 if (regexpFlags !== @regExpProtoFlagsGetter) 443 443 return true; 444 444 445 445 // These are accessed by the builtin flags getter. 446 letregexpGlobal = @tryGetById(regexp, "global");446 var regexpGlobal = @tryGetById(regexp, "global"); 447 447 if (regexpGlobal !== @regExpProtoGlobalGetter) 448 448 return true; 449 letregexpIgnoreCase = @tryGetById(regexp, "ignoreCase");449 var regexpIgnoreCase = @tryGetById(regexp, "ignoreCase"); 450 450 if (regexpIgnoreCase !== @regExpProtoIgnoreCaseGetter) 451 451 return true; 452 letregexpMultiline = @tryGetById(regexp, "multiline");452 var regexpMultiline = @tryGetById(regexp, "multiline"); 453 453 if (regexpMultiline !== @regExpProtoMultilineGetter) 454 454 return true; 455 letregexpSticky = @tryGetById(regexp, "sticky");455 var regexpSticky = @tryGetById(regexp, "sticky"); 456 456 if (regexpSticky !== @regExpProtoStickyGetter) 457 457 return true; 458 letregexpUnicode = @tryGetById(regexp, "unicode");458 var regexpUnicode = @tryGetById(regexp, "unicode"); 459 459 if (regexpUnicode !== @regExpProtoUnicodeGetter) 460 460 return true; 461 461 462 462 // This is accessed by the RegExp species constructor. 463 letregexpSource = @tryGetById(regexp, "source");463 var regexpSource = @tryGetById(regexp, "source"); 464 464 if (regexpSource !== @regExpProtoSourceGetter) 465 465 return true; … … 478 478 if (!@isObject(this)) 479 479 @throwTypeError("RegExp.prototype.@@split requires that |this| be an Object"); 480 letregexp = this;480 var regexp = this; 481 481 482 482 // 3. Let S be ? ToString(string). 483 letstr = @toString(string);483 var str = @toString(string); 484 484 485 485 // 4. Let C be ? SpeciesConstructor(rx, %RegExp%). 486 letspeciesConstructor = @speciesConstructor(regexp, @RegExp);486 var speciesConstructor = @speciesConstructor(regexp, @RegExp); 487 487 488 488 if (speciesConstructor === @RegExp && !@hasObservableSideEffectsForRegExpSplit(regexp)) … … 490 490 491 491 // 5. Let flags be ? ToString(? Get(rx, "flags")). 492 letflags = @toString(regexp.flags);493 494 // 6. If flags contains "u", letunicodeMatching be true.492 var flags = @toString(regexp.flags); 493 494 // 6. If flags contains "u", var unicodeMatching be true. 495 495 // 7. Else, let unicodeMatching be false. 496 letunicodeMatching = @stringIncludesInternal.@call(flags, "u");497 // 8. If flags contains "y", letnewFlags be flags.496 var unicodeMatching = @stringIncludesInternal.@call(flags, "u"); 497 // 8. If flags contains "y", var newFlags be flags. 498 498 // 9. Else, let newFlags be the string that is the concatenation of flags and "y". 499 letnewFlags = @stringIncludesInternal.@call(flags, "y") ? flags : flags + "y";499 var newFlags = @stringIncludesInternal.@call(flags, "y") ? flags : flags + "y"; 500 500 501 501 // 10. Let splitter be ? Construct(C, « rx, newFlags »). 502 letsplitter = new speciesConstructor(regexp, newFlags);502 var splitter = new speciesConstructor(regexp, newFlags); 503 503 504 504 // We need to check again for RegExp subclasses that will fail the speciesConstructor test … … 509 509 // 11. Let A be ArrayCreate(0). 510 510 // 12. Let lengthA be 0. 511 letresult = [];512 513 // 13. If limit is undefined, let lim be 2^32-1; else letlim be ? ToUint32(limit).511 var result = []; 512 513 // 13. If limit is undefined, let lim be 2^32-1; else var lim be ? ToUint32(limit). 514 514 limit = (limit === @undefined) ? 0xffffffff : limit >>> 0; 515 515 … … 519 519 520 520 // 14. [Defered from above] Let size be the number of elements in S. 521 letsize = str.length;521 var size = str.length; 522 522 523 523 // 17. If size = 0, then 524 524 if (!size) { 525 525 // a. Let z be ? RegExpExec(splitter, S). 526 letz = @regExpExec(splitter, str);526 var z = @regExpExec(splitter, str); 527 527 // b. If z is not null, return A. 528 528 if (z != null) … … 535 535 536 536 // 15. [Defered from above] Let p be 0. 537 letposition = 0;537 var position = 0; 538 538 // 18. Let q be p. 539 letmatchPosition = 0;539 var matchPosition = 0; 540 540 541 541 // 19. Repeat, while q < size … … 544 544 splitter.lastIndex = matchPosition; 545 545 // b. Let z be ? RegExpExec(splitter, S). 546 letmatches = @regExpExec(splitter, str);546 var matches = @regExpExec(splitter, str); 547 547 // c. If z is null, let q be AdvanceStringIndex(S, q, unicodeMatching). 548 548 if (matches === null) … … 551 551 else { 552 552 // i. Let e be ? ToLength(? Get(splitter, "lastIndex")). 553 letendPosition = @toLength(splitter.lastIndex);553 var endPosition = @toLength(splitter.lastIndex); 554 554 // ii. Let e be min(e, size). 555 555 endPosition = (endPosition <= size) ? endPosition : size; … … 560 560 else { 561 561 // 1. Let T be a String value equal to the substring of S consisting of the elements at indices p (inclusive) through q (exclusive). 562 letsubStr = @stringSubstrInternal.@call(str, position, matchPosition - position);562 var subStr = @stringSubstrInternal.@call(str, position, matchPosition - position); 563 563 // 2. Perform ! CreateDataProperty(A, ! ToString(lengthA), T). 564 564 // 3. Let lengthA be lengthA + 1. … … 572 572 // 6. Let numberOfCaptures be ? ToLength(? Get(z, "length")). 573 573 // 7. Let numberOfCaptures be max(numberOfCaptures-1, 0). 574 letnumberOfCaptures = matches.length > 1 ? matches.length - 1 : 0;574 var numberOfCaptures = matches.length > 1 ? matches.length - 1 : 0; 575 575 576 576 // 8. Let i be 1. 577 leti = 1;577 var i = 1; 578 578 // 9. Repeat, while i <= numberOfCaptures, 579 579 while (i <= numberOfCaptures) { 580 580 // a. Let nextCapture be ? Get(z, ! ToString(i)). 581 letnextCapture = matches[i];581 var nextCapture = matches[i]; 582 582 // b. Perform ! CreateDataProperty(A, ! ToString(lengthA), nextCapture). 583 583 // d. Let lengthA be lengthA + 1. … … 595 595 } 596 596 // 20. Let T be a String value equal to the substring of S consisting of the elements at indices p (inclusive) through size (exclusive). 597 letremainingStr = @stringSubstrInternal.@call(str, position, size);597 var remainingStr = @stringSubstrInternal.@call(str, position, size); 598 598 // 21. Perform ! CreateDataProperty(A, ! ToString(lengthA), T). 599 599 @putByValDirect(result, result.length, remainingStr); … … 608 608 "use strict"; 609 609 610 letregexp = this;610 var regexp = this; 611 611 612 612 // Check for observable side effects and call the fast path if there aren't any. … … 622 622 623 623 // 3. Let string be ? ToString(S). 624 letstr = @toString(strArg);624 var str = @toString(strArg); 625 625 626 626 // 4. Let match be ? RegExpExec(R, string). 627 letmatch = @regExpExec(regexp, str);627 var match = @regExpExec(regexp, str); 628 628 629 629 // 5. If match is not null, return true; else return false. -
trunk/Source/JavaScriptCore/builtins/RegExpStringIteratorPrototype.js
r246567 r254418 31 31 @throwTypeError("%RegExpStringIteratorPrototype%.next requires |this| to be an Object"); 32 32 33 letdone = @getByIdDirectPrivate(this, "regExpStringIteratorDone");33 var done = @getByIdDirectPrivate(this, "regExpStringIteratorDone"); 34 34 if (done === @undefined) 35 35 @throwTypeError("%RegExpStringIteratorPrototype%.next requires |this| to be an RegExp String Iterator instance"); … … 38 38 return { value: @undefined, done: true }; 39 39 40 letregExp = @getByIdDirectPrivate(this, "regExpStringIteratorRegExp");41 letstring = @getByIdDirectPrivate(this, "regExpStringIteratorString");42 letglobal = @getByIdDirectPrivate(this, "regExpStringIteratorGlobal");43 letfullUnicode = @getByIdDirectPrivate(this, "regExpStringIteratorUnicode");44 letmatch = @regExpExec(regExp, string);40 var regExp = @getByIdDirectPrivate(this, "regExpStringIteratorRegExp"); 41 var string = @getByIdDirectPrivate(this, "regExpStringIteratorString"); 42 var global = @getByIdDirectPrivate(this, "regExpStringIteratorGlobal"); 43 var fullUnicode = @getByIdDirectPrivate(this, "regExpStringIteratorUnicode"); 44 var match = @regExpExec(regExp, string); 45 45 if (match === null) { 46 46 @putByIdDirectPrivate(this, "regExpStringIteratorDone", true); … … 49 49 50 50 if (global) { 51 letmatchStr = @toString(match[0]);51 var matchStr = @toString(match[0]); 52 52 if (matchStr === "") { 53 letthisIndex = @toLength(regExp.lastIndex);53 var thisIndex = @toLength(regExp.lastIndex); 54 54 regExp.lastIndex = @advanceStringIndex(string, thisIndex, fullUnicode); 55 55 } -
trunk/Source/JavaScriptCore/builtins/StringPrototype.js
r252754 r254418 39 39 } 40 40 41 letthisString = @toString(this);42 letcreatedRegExp = @regExpCreate(regexp, @undefined);41 var thisString = @toString(this); 42 var createdRegExp = @regExpCreate(regexp, @undefined); 43 43 return createdRegExp.@matchSymbol(thisString); 44 44 } … … 55 55 @throwTypeError("String.prototype.matchAll argument must not be a non-global regular expression"); 56 56 57 letmatcher = arg.@matchAllSymbol;57 var matcher = arg.@matchAllSymbol; 58 58 if (!@isUndefinedOrNull(matcher)) 59 59 return matcher.@call(arg, this); 60 60 } 61 61 62 letstring = @toString(this);63 letregExp = @regExpCreate(arg, "g");62 var string = @toString(this); 63 var regExp = @regExpCreate(arg, "g"); 64 64 return regExp.@matchAllSymbol(string); 65 65 } … … 223 223 return true; 224 224 225 letregexpExec = @tryGetById(regexp, "exec");225 var regexpExec = @tryGetById(regexp, "exec"); 226 226 if (regexpExec !== @regExpBuiltinExec) 227 227 return true; 228 228 229 letregexpGlobal = @tryGetById(regexp, "global");229 var regexpGlobal = @tryGetById(regexp, "global"); 230 230 if (regexpGlobal !== @regExpProtoGlobalGetter) 231 231 return true; 232 232 233 letregexpUnicode = @tryGetById(regexp, "unicode");233 var regexpUnicode = @tryGetById(regexp, "unicode"); 234 234 if (regexpUnicode !== @regExpProtoUnicodeGetter) 235 235 return true; … … 247 247 248 248 if (search != null) { 249 let replacer = search.@replaceSymbol;250 if (replacer !== @undefined) {251 if (!@hasObservableSideEffectsForStringReplace(search, replacer))252 return @toString(this).@replaceUsingRegExp(search, replace);253 return replacer.@call(search, this, replace);254 }255 }256 257 let thisString = @toString(this);258 let searchString = @toString(search);259 return thisString.@replaceUsingStringSearch(searchString, replace);260 }261 262 function replaceAll(search, replace)263 {264 "use strict";265 266 if (@isUndefinedOrNull(this))267 @throwTypeError("String.prototype.replaceAll requires |this| not to be null nor undefined");268 269 if (search != null) {270 if (@isRegExp(search) && !@stringIncludesInternal.@call(@toString(search.flags), "g"))271 @throwTypeError("String.prototype.replaceAll argument must not be a non-global regular expression");272 273 249 var replacer = search.@replaceSymbol; 274 250 if (replacer !== @undefined) { … … 281 257 var thisString = @toString(this); 282 258 var searchString = @toString(search); 259 return thisString.@replaceUsingStringSearch(searchString, replace); 260 } 261 262 function replaceAll(search, replace) 263 { 264 "use strict"; 265 266 if (@isUndefinedOrNull(this)) 267 @throwTypeError("String.prototype.replaceAll requires |this| not to be null nor undefined"); 268 269 if (search != null) { 270 if (@isRegExp(search) && !@stringIncludesInternal.@call(@toString(search.flags), "g")) 271 @throwTypeError("String.prototype.replaceAll argument must not be a non-global regular expression"); 272 273 var replacer = search.@replaceSymbol; 274 if (replacer !== @undefined) { 275 if (!@hasObservableSideEffectsForStringReplace(search, replacer)) 276 return @toString(this).@replaceUsingRegExp(search, replace); 277 return replacer.@call(search, this, replace); 278 } 279 } 280 281 var thisString = @toString(this); 282 var searchString = @toString(search); 283 283 return thisString.@replaceAllUsingStringSearch(searchString, replace); 284 284 } … … 347 347 if (@isUndefinedOrNull(string)) 348 348 @throwTypeError(`${func} requires that |this| not be null or undefined`); 349 letS = @toString(string);350 letp1 = "<" + tag;349 var S = @toString(string); 350 var p1 = "<" + tag; 351 351 if (attribute) { 352 letV = @toString(value);353 letescapedV = V.@replaceUsingRegExp(/"/g, '"');352 var V = @toString(value); 353 var escapedV = V.@replaceUsingRegExp(/"/g, '"'); 354 354 p1 = p1 + " " + @toString(attribute) + '="' + escapedV + '"' 355 355 } 356 letp2 = p1 + ">"357 letp3 = p2 + S;358 letp4 = p3 + "</" + tag + ">";356 var p2 = p1 + ">" 357 var p3 = p2 + S; 358 var p4 = p3 + "</" + tag + ">"; 359 359 return p4; 360 360 } -
trunk/Source/JavaScriptCore/builtins/TypedArrayConstructor.js
r230376 r254418 32 32 { 33 33 "use strict"; 34 letlen = arguments.length;35 letconstructFunction = @getByIdDirectPrivate(this, "allocateTypedArray");34 var len = arguments.length; 35 var constructFunction = @getByIdDirectPrivate(this, "allocateTypedArray"); 36 36 if (constructFunction === @undefined) 37 37 @throwTypeError("TypedArray.of requires its this argument to subclass a TypedArray constructor"); 38 38 39 letresult = constructFunction(len);39 var result = constructFunction(len); 40 40 41 for ( leti = 0; i < len; i++)41 for (var i = 0; i < len; i++) 42 42 result[i] = arguments[i]; 43 43 … … 49 49 "use strict"; 50 50 51 letmapFn = @argument(1);51 var mapFn = @argument(1); 52 52 53 letthisArg;53 var thisArg; 54 54 55 55 if (mapFn !== @undefined) { … … 60 60 } 61 61 62 letarrayLike = @toObject(items, "TypedArray.from requires an array-like object - not null or undefined");62 var arrayLike = @toObject(items, "TypedArray.from requires an array-like object - not null or undefined"); 63 63 64 letiteratorMethod = items.@iteratorSymbol;64 var iteratorMethod = items.@iteratorSymbol; 65 65 if (iteratorMethod != null) { 66 66 if (typeof iteratorMethod !== "function") 67 67 @throwTypeError("TypedArray.from requires that the property of the first argument, items[Symbol.iterator], when exists, be a function"); 68 68 69 letaccumulator = [];69 var accumulator = []; 70 70 71 letk = 0;72 letiterator = iteratorMethod.@call(items);71 var k = 0; 72 var iterator = iteratorMethod.@call(items); 73 73 74 74 // Since for-of loop once more looks up the @@iterator property of a given iterable, 75 75 // it could be observable if the user defines a getter for @@iterator. 76 76 // To avoid this situation, we define a wrapper object that @@iterator just returns a given iterator. 77 letwrapper = {};77 var wrapper = {}; 78 78 wrapper.@iteratorSymbol = function() { return iterator; } 79 79 80 for ( letvalue of wrapper) {80 for (var value of wrapper) { 81 81 if (mapFn) 82 82 @putByValDirect(accumulator, k, thisArg === @undefined ? mapFn(value, k) : mapFn.@call(thisArg, value, k)); … … 86 86 } 87 87 88 letconstructFunction = @getByIdDirectPrivate(this, "allocateTypedArray");88 var constructFunction = @getByIdDirectPrivate(this, "allocateTypedArray"); 89 89 if (constructFunction === @undefined) 90 90 @throwTypeError("TypedArray.from requires its this argument subclass a TypedArray constructor"); 91 91 92 letresult = constructFunction(k);92 var result = constructFunction(k); 93 93 94 for ( leti = 0; i < k; i++)94 for (var i = 0; i < k; i++) 95 95 result[i] = accumulator[i]; 96 96 … … 99 99 } 100 100 101 letarrayLikeLength = @toLength(arrayLike.length);101 var arrayLikeLength = @toLength(arrayLike.length); 102 102 103 letconstructFunction = @getByIdDirectPrivate(this, "allocateTypedArray");103 var constructFunction = @getByIdDirectPrivate(this, "allocateTypedArray"); 104 104 if (constructFunction === @undefined) 105 105 @throwTypeError("this does not subclass a TypedArray constructor"); 106 106 107 letresult = constructFunction(arrayLikeLength);107 var result = constructFunction(arrayLikeLength); 108 108 109 letk = 0;109 var k = 0; 110 110 while (k < arrayLikeLength) { 111 letvalue = arrayLike[k];111 var value = arrayLike[k]; 112 112 if (mapFn) 113 113 result[k] = thisArg === @undefined ? mapFn(value, k) : mapFn.@call(thisArg, value, k); -
trunk/Source/JavaScriptCore/builtins/TypedArrayPrototype.js
r254252 r254418 36 36 { 37 37 "use strict"; 38 letconstructor = value.constructor;38 var constructor = value.constructor; 39 39 if (constructor === @undefined) 40 40 return @typedArrayGetOriginalConstructor(value); … … 61 61 return undefinedValue; 62 62 63 letint = @toInteger(value);63 var int = @toInteger(value); 64 64 if (int < 0) { 65 65 int += length; … … 90 90 "use strict"; 91 91 92 letlength = @typedArrayLength(this);93 94 letstart = @argument(1);95 letend = @argument(2);92 var length = @typedArrayLength(this); 93 94 var start = @argument(1); 95 var end = @argument(2); 96 96 97 97 start = @typedArrayClampArgumentToStartOrEnd(start, length, 0); 98 98 end = @typedArrayClampArgumentToStartOrEnd(end, length, length); 99 99 100 for ( leti = start; i < end; i++)100 for (var i = start; i < end; i++) 101 101 this[i] = value; 102 102 return this; … … 113 113 114 114 for (var i = 0; i < length; i++) { 115 letelem = this[i];115 var elem = this[i]; 116 116 if (callback.@call(thisArg, elem, i, this)) 117 117 return elem; … … 239 239 @throwTypeError("|this| should be a typed array view"); 240 240 241 letstart = @toInteger(begin);242 letfinish;241 var start = @toInteger(begin); 242 var finish; 243 243 if (end !== @undefined) 244 244 finish = @toInteger(end); 245 245 246 letconstructor = @typedArraySpeciesConstructor(this);246 var constructor = @typedArraySpeciesConstructor(this); 247 247 248 248 return @typedArraySubarrayCreate.@call(this, start, finish, constructor);
Note: See TracChangeset
for help on using the changeset viewer.