Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions std/StringTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class StringTools {
#elseif neko
return untyped new String(_urlEncode(s.__s));
#elseif js
return untyped encodeURIComponent(s);
return js.Lib.global.encodeURIComponent(s);
#elseif cpp
return untyped s.__URLEncode();
#elseif java
Expand Down Expand Up @@ -111,7 +111,7 @@ class StringTools {
#elseif neko
return untyped new String(_urlDecode(s.__s));
#elseif js
return untyped decodeURIComponent(s.split("+").join(" "));
return js.Lib.global.decodeURIComponent(s.split("+").join(" "));
#elseif cpp
return untyped s.__URLDecode();
#elseif java
Expand Down
2 changes: 1 addition & 1 deletion std/cpp/_std/Std.hx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
}

@:keep public static function string(s:Dynamic):String {
return untyped s == null ? "null" : s.toString();
return s == null ? "null" : s.toString();
}

@:keep public static function int(x:Float):Int {
Expand Down
8 changes: 4 additions & 4 deletions std/cpp/_std/sys/io/File.hx
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ class File {
}

public static function read(path:String, binary:Bool = true):FileInput {
return untyped new FileInput(NativeFile.file_open(path, (if (binary) "rb" else "r")));
return @:privateAccess new FileInput(NativeFile.file_open(path, (if (binary) "rb" else "r")));
}

public static function write(path:String, binary:Bool = true):FileOutput {
return untyped new FileOutput(NativeFile.file_open(path, (if (binary) "wb" else "w")));
return @:privateAccess new FileOutput(NativeFile.file_open(path, (if (binary) "wb" else "w")));
}

public static function append(path:String, binary:Bool = true):FileOutput {
return untyped new FileOutput(NativeFile.file_open(path, (if (binary) "ab" else "a")));
return @:privateAccess new FileOutput(NativeFile.file_open(path, (if (binary) "ab" else "a")));
}

public static function update(path:String, binary:Bool = true):FileOutput {
if (!FileSystem.exists(path)) {
write(path).close();
}
return untyped new FileOutput(NativeFile.file_open(path, (if (binary) "rb+" else "r+")));
return @:privateAccess new FileOutput(NativeFile.file_open(path, (if (binary) "rb+" else "r+")));
}

public static function copy(srcPath:String, dstPath:String):Void {
Expand Down
4 changes: 2 additions & 2 deletions std/haxe/DynamicAccess.hx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ abstract DynamicAccess<T>(Dynamic<T>) from Dynamic<T> to Dynamic<T> {
@:arrayAccess
public inline function get(key:String):Null<T> {
#if js
return untyped this[key]; // we know it's an object, so we don't need a check
return js.Syntax.code("{0}[{1}]", this, key); // we know it's an object, so we don't need a check
#else
return Reflect.field(this, key);
#end
Expand All @@ -68,7 +68,7 @@ abstract DynamicAccess<T>(Dynamic<T>) from Dynamic<T> to Dynamic<T> {
@:arrayAccess
public inline function set(key:String, value:T):T {
#if js
return untyped this[key] = value;
return js.Syntax.code("{0}[{1}] = {2}", this, key, value);
#else
Reflect.setField(this, key, value);
return value;
Expand Down
2 changes: 1 addition & 1 deletion std/haxe/EntryPoint.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class EntryPoint {
var nextTick = haxe.EventLoop.main.getNextTick();
inline function setTimeoutNextTick() {
if (nextTick >= 0) {
(untyped setTimeout)(run, nextTick * 1000);
js.Lib.global.setTimeout(run, nextTick * 1000);
}
}
#if nodejs
Expand Down
7 changes: 5 additions & 2 deletions std/haxe/Int32.hx
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ abstract Int32(Int) from Int to Int {
@:op(A * B) inline static function mul(a:Int32, b:Int32):Int32
return _mul(a, b);

static var _mul:Int32->Int32->Int32 = untyped if (Math.imul != null)
Math.imul
static var _mul:Int32->Int32->Int32 = {
final imul:Dynamic = (cast Math : Dynamic).imul;
if (imul != null)
cast imul
else
function(a:Int32, b:Int32):Int32 return clamp((a : Int) * ((b : Int) & 0xFFFF) + clamp((a : Int) * ((b : Int) >>> 16) << 16));
}
#else
@:op(A * B) private static function mul(a:Int32, b:Int32):Int32
return clamp((a : Int) * ((b : Int) & 0xFFFF) + clamp((a : Int) * ((b : Int) >>> 16) << 16));
Expand Down
5 changes: 3 additions & 2 deletions std/haxe/Log.hx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ class Log {
public static dynamic function trace(v:Dynamic, ?infos:PosInfos):Void {
var str = formatOutput(v, infos);
#if js
if (js.Syntax.typeof(untyped console) != "undefined" && (untyped console).log != null)
(untyped console).log(str);
var console = js.Lib.global.console;
if (js.Syntax.typeof(console) != "undefined" && console.log != null)
console.log(str);
#elseif lua
untyped __define_feature__("use._hx_print", _hx_print(str));
#elseif sys
Expand Down
4 changes: 2 additions & 2 deletions std/haxe/Timer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Timer {
}, time_ms);
#elseif js
var me = this;
id = untyped setInterval(function() me.run(), time_ms);
id = js.Lib.global.setInterval(function() me.run(), time_ms);
#else
event = EventLoop.current.addTimer(() -> this.run(), time_ms/1000.);
#end
Expand All @@ -90,7 +90,7 @@ class Timer {
#if flash
untyped __global__["flash.utils.clearInterval"](id);
#elseif js
untyped clearInterval(id);
js.Lib.global.clearInterval(id);
#end
id = null;
#else
Expand Down
2 changes: 1 addition & 1 deletion std/haxe/rtti/Meta.hx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Meta {
var t:hl.BaseType = t;
return t.__meta__;
#else
return untyped t.__meta__;
return t.__meta__;
#end
}

Expand Down
2 changes: 1 addition & 1 deletion std/js/Boot.hx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class Boot {
}
var tostr;
try {
tostr = untyped o.toString;
tostr = o.toString;
} catch (e:Dynamic) {
// strange error on IE
return "???";
Expand Down
2 changes: 1 addition & 1 deletion std/js/Cookie.hx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Cookie {
var s = name + "=" + StringTools.urlEncode(value);
if (expireDelay != null) {
var d = DateTools.delta(Date.now(), expireDelay * 1000);
s += ";expires=" + untyped d.toGMTString();
s += ";expires=" + (d : Dynamic).toGMTString();
}
if (path != null) {
s += ";path=" + path;
Expand Down
4 changes: 2 additions & 2 deletions std/js/Selection.hx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Selection {
if (doc.selectionStart != null)
return doc.value.substring(doc.selectionStart, doc.selectionEnd);
// IE
var range = untyped js.Lib.document.selection.createRange();
var range = (js.Lib.document : Dynamic).selection.createRange();
if (range.parentElement() != doc)
return "";
return range.text;
Expand Down Expand Up @@ -92,7 +92,7 @@ class Selection {
return;
}
// IE
var range = untyped js.Lib.document.selection.createRange();
var range = (js.Lib.document : Dynamic).selection.createRange();
range.text = left + text + right;
range.moveStart('character', -text.length - right.length);
range.moveEnd('character', -right.length);
Expand Down
2 changes: 1 addition & 1 deletion std/js/_std/Reflect.hx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@

public static function makeVarArgs<T>(f:Array<Dynamic>->T):Dynamic {
return function() {
var a = untyped Array.prototype.slice.call(js.Syntax.code("arguments"));
var a:Array<Dynamic> = js.Syntax.code("Array.prototype.slice.call(arguments)");
return f(a);
};
}
Expand Down
8 changes: 4 additions & 4 deletions std/js/_std/haxe/ds/ObjectMap.hx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ObjectMap<K:{}, V> implements haxe.Constraints.IMap<K, V> {
}

static inline function getId(obj:{}):Int {
return untyped obj.__id__;
return Syntax.code("{0}.__id__", obj);
}

var h:{__keys__:{}};
Expand All @@ -118,16 +118,16 @@ class ObjectMap<K:{}, V> implements haxe.Constraints.IMap<K, V> {
}

public inline function get(key:K):Null<V> {
return untyped h[getId(key)];
return Syntax.code("{0}[{1}]", h, getId(key));
}

public inline function exists(key:K):Bool {
return untyped h.__keys__[getId(key)] != null;
return Syntax.code("{0}[{1}] != null", h.__keys__, getId(key));
}

public function remove(key:K):Bool {
var id = getId(key);
if (untyped h.__keys__[id] == null)
if (Syntax.code("{0}[{1}] == null", h.__keys__, id))
return false;
js.Syntax.delete(h, id);
js.Syntax.delete(h.__keys__, id);
Expand Down
3 changes: 1 addition & 2 deletions std/js/lib/ArrayBuffer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ private class ArrayBufferCompat {
return resultArray.buffer;
}

static function __init__():Void
untyped {
static function __init__():Void {
// IE10 ArrayBuffer.slice polyfill
if (js.Syntax.code("ArrayBuffer").prototype.slice == null)
js.Syntax.code("ArrayBuffer").prototype.slice = sliceImpl;
Expand Down
6 changes: 3 additions & 3 deletions std/jvm/_std/EReg.hx
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ using StringTools;
}

public function matchedLeft():String {
return untyped cur.substring(0, matcher.start());
return cur.substring(0, matcher.start());
}

public function matchedRight():String {
return untyped cur.substring(matcher.end(), cur.length);
return cur.substring(matcher.end(), cur.length);
}

public function matchedPos():{pos:Int, len:Int} {
Expand Down Expand Up @@ -117,7 +117,7 @@ using StringTools;
var m = matcher;
m.reset(s);
if (m.find()) {
return untyped [s.substring(0, m.start()), s.substring(m.end(), s.length)];
return [s.substring(0, m.start()), s.substring(m.end(), s.length)];
} else {
return [s];
}
Expand Down
4 changes: 2 additions & 2 deletions std/jvm/_std/haxe/ds/WeakMap.hx
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ import java.lang.ref.ReferenceQueue;

// guarantee: Whatever this function is, it will never return 0 nor 1
extern private static inline function hash(s:Dynamic):HashType {
var k:Int = untyped s.hashCode();
var k:Int = (cast s : java.lang.Object).hashCode();
// k *= 357913941;
// k ^= k << 24;
// k += ~357913941;
Expand Down Expand Up @@ -512,7 +512,7 @@ private class Entry<K, V> extends WeakReference<K> {
}

final inline public function keyEquals(k:K):Bool {
return k != null && untyped k.equals(get());
return k != null && (cast k : java.lang.Object).equals(get());
}
}

Expand Down
8 changes: 5 additions & 3 deletions std/lua/_std/Std.hx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ import lua.NativeStringTools;
return isOfType(v, t);
}

@:access(lua.Boot)
public static inline function isOfType(v:Dynamic, t:Dynamic):Bool {
return untyped lua.Boot.__instanceof(v, t);
return lua.Boot.__instanceof(v, t);
}

@:access(lua.Boot)
public static inline function downcast<T:{}, S:T>(value:T, c:Class<S>):Null<S> {
return untyped lua.Boot.__instanceof(value, c) ? cast value : null;
return lua.Boot.__instanceof(value, c) ? cast value : null;
}

@:deprecated('Std.instance() is deprecated. Use Std.downcast() instead.')
Expand Down Expand Up @@ -94,6 +96,6 @@ import lua.NativeStringTools;
}

public static function random(x:Int):Int {
return untyped x <= 0 ? 0 : Math.floor(Math.random() * x);
return x <= 0 ? 0 : Math.floor(Math.random() * x);
}
}
3 changes: 2 additions & 1 deletion std/neko/_std/Std.hx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
return isOfType(v, t);
}

@:access(neko.Boot)
public static function isOfType(v:Dynamic, t:Dynamic):Bool {
return untyped neko.Boot.__instanceof(v, t);
return neko.Boot.__instanceof(v, t);
}

public static function downcast<T:{}, S:T>(value:T, c:Class<S>):Null<S> {
Expand Down
6 changes: 3 additions & 3 deletions std/neko/_std/Sys.hx
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ import haxe.SysTools;
}

public static function stdin() : haxe.io.Input {
return untyped new sys.io.FileInput(file_stdin());
return @:privateAccess new sys.io.FileInput(file_stdin());
}

public static function stdout() : haxe.io.Output {
return untyped new sys.io.FileOutput(file_stdout());
return @:privateAccess new sys.io.FileOutput(file_stdout());
}

public static function stderr() : haxe.io.Output {
return untyped new sys.io.FileOutput(file_stderr());
return @:privateAccess new sys.io.FileOutput(file_stderr());
}

public static function args() : Array<String> untyped {
Expand Down
6 changes: 3 additions & 3 deletions std/php/_std/sys/io/File.hx
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ import php.Global;
}

public static function write(path:String, binary:Bool = true):FileOutput {
return untyped new FileOutput(fopen(path, binary ? "wb" : "w"));
return @:privateAccess new FileOutput(fopen(path, binary ? "wb" : "w"));
}

public static function append(path:String, binary:Bool = true):FileOutput {
return untyped new FileOutput(fopen(path, binary ? "ab" : "a"));
return @:privateAccess new FileOutput(fopen(path, binary ? "ab" : "a"));
}

public static function update(path:String, binary:Bool = true):FileOutput {
if (!FileSystem.exists(path)) {
write(path).close();
}
return untyped new FileOutput(fopen(path, binary ? "rb+" : "r+"));
return @:privateAccess new FileOutput(fopen(path, binary ? "rb+" : "r+"));
}

public static function copy(srcPath:String, dstPath:String):Void {
Expand Down
Loading