Переглянути джерело

[js] add NativeString with correct charCodeAt signature

Rudy Ges 4 місяців тому
батько
коміт
755e644036
2 змінених файлів з 10 додано та 4 видалено
  1. 4 4
      std/StringTools.hx
  2. 6 0
      std/js/NativeString.hx

+ 4 - 4
std/StringTools.hx

@@ -454,7 +454,7 @@ class StringTools {
 		This operation is not guaranteed to work if `s` contains the `\0`
 		character.
 	**/
-	public static #if !eval inline #end function fastCodeAt(s:String, index:Int):Null<Int> {
+	public static #if !eval inline #end function fastCodeAt(s:String, index:Int):Int {
 		#if neko
 		return untyped __dollar__sget(s.__s, index);
 		#elseif cpp
@@ -464,7 +464,7 @@ class StringTools {
 		#elseif java
 		return (index < s.length) ? cast(_charAt(s, index), Int) : -1;
 		#elseif js
-		return (cast s).charCodeAt(index);
+		return (cast s:js.NativeString).charCodeAt(index);
 		#elseif python
 		return if (index >= s.length) -1 else python.internal.UBuiltins.ord(python.Syntax.arrayAccess(s, index));
 		#elseif hl
@@ -491,7 +491,7 @@ class StringTools {
 		This operation is not guaranteed to work if `s` contains the `\0`
 		character.
 	**/
-	public static #if !eval inline #end function unsafeCodeAt(s:String, index:Int):Null<Int> {
+	public static #if !eval inline #end function unsafeCodeAt(s:String, index:Int):Int {
 		#if neko
 		return untyped __dollar__sget(s.__s, index);
 		#elseif cpp
@@ -501,7 +501,7 @@ class StringTools {
 		#elseif java
 		return cast(_charAt(s, index), Int);
 		#elseif js
-		return (cast s).charCodeAt(index);
+		return (cast s:js.NativeString).charCodeAt(index);
 		#elseif python
 		return python.internal.UBuiltins.ord(python.Syntax.arrayAccess(s, index));
 		#elseif hl

+ 6 - 0
std/js/NativeString.hx

@@ -0,0 +1,6 @@
+package js;
+
+@:native("String")
+extern class NativeString {
+	@:pure function charCodeAt(index:Int):Int;
+}