Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: compiler/lib/implementation/string.js

Issue 8241013: Pull "$instanceOf" methods off of the native object. No change in behavior. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « compiler/lib/implementation/rtt.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /**
6 * Extend the String prototype with members expected in dart.
7 */
8
9 String.$instanceOf = function(obj) {
10 return typeof obj == 'string' || obj instanceof String;
11 };
12
13 function native_StringImplementation__indexOperator(index) { 5 function native_StringImplementation__indexOperator(index) {
14 return this[index]; 6 return this[index];
15 } 7 }
16 8
17 function native_StringImplementation__charCodeAt(index) { 9 function native_StringImplementation__charCodeAt(index) {
18 return this.charCodeAt(index); 10 return this.charCodeAt(index);
19 } 11 }
20 12
21 function native_StringImplementation_get$length() { 13 function native_StringImplementation_get$length() {
22 return this.length; 14 return this.length;
(...skipping 28 matching lines...) Expand all
51 function native_StringImplementation__substringUnchecked(startIndex, endIndex) { 43 function native_StringImplementation__substringUnchecked(startIndex, endIndex) {
52 return this.substring(startIndex, endIndex); 44 return this.substring(startIndex, endIndex);
53 } 45 }
54 46
55 function native_StringImplementation_trim() { 47 function native_StringImplementation_trim() {
56 if (this.trim) return this.trim(); 48 if (this.trim) return this.trim();
57 return this.replace(new RegExp("^[\s]+|[\s]+$", "g"), ""); 49 return this.replace(new RegExp("^[\s]+|[\s]+$", "g"), "");
58 } 50 }
59 51
60 function native_StringImplementation__replace(from, to) { 52 function native_StringImplementation__replace(from, to) {
61 if (String.$instanceOf(from)) { 53 if ($isString(from)) {
62 return this.replace(from, to); 54 return this.replace(from, to);
63 } else { 55 } else {
64 return this.replace($DartRegExpToJSRegExp(from), to); 56 return this.replace($DartRegExpToJSRegExp(from), to);
65 } 57 }
66 } 58 }
67 59
68 function native_StringImplementation__replaceAll(from, to) { 60 function native_StringImplementation__replaceAll(from, to) {
69 if (String.$instanceOf(from)) { 61 if ($isString(from)) {
70 var regexp = new RegExp( 62 var regexp = new RegExp(
71 from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'g'); 63 from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'g');
72 return this.replace(regexp, to); 64 return this.replace(regexp, to);
73 } else { 65 } else {
74 var regexp = $DartRegExpToJSRegExp(from); 66 var regexp = $DartRegExpToJSRegExp(from);
75 return this.replace(regexp, to); 67 return this.replace(regexp, to);
76 } 68 }
77 } 69 }
78 70
79 function native_StringImplementation__split(pattern) { 71 function native_StringImplementation__split(pattern) {
80 if (String.$instanceOf(pattern)) { 72 if ($isString(pattern)) {
81 return this.split(pattern); 73 return this.split(pattern);
82 } else { 74 } else {
83 return this.split($DartRegExpToJSRegExp(pattern)); 75 return this.split($DartRegExpToJSRegExp(pattern));
84 } 76 }
85 } 77 }
86 78
87 function native_StringImplementation_toLowerCase() { 79 function native_StringImplementation_toLowerCase() {
88 return this.toLowerCase(); 80 return this.toLowerCase();
89 } 81 }
90 82
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 } 124 }
133 array = tmp; 125 array = tmp;
134 } 126 }
135 return String.fromCharCode.apply(this, array); 127 return String.fromCharCode.apply(this, array);
136 } 128 }
137 129
138 // Deprecated old name of new String.fromValues(..). 130 // Deprecated old name of new String.fromValues(..).
139 function native_StringBase_createFromCharCodes(array) { 131 function native_StringBase_createFromCharCodes(array) {
140 return native_StringImplementation__newFromValues(array); 132 return native_StringImplementation__newFromValues(array);
141 } 133 }
OLDNEW
« no previous file with comments | « compiler/lib/implementation/rtt.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698