Skip to content

Commit

Permalink
Neko soft deprecate : split off conditional compilation into separate…
Browse files Browse the repository at this point in the history
… impl (HaxeFoundation#9350)

* split off neko haxe/Resource.hx into separate impl

* split off more unique neko conditionals into separate implementations

* fix return type on neko haxe.Resource

* strip comments from neko/_std/haxe/format/JsonPrinter.hx

* revert neko JsonPrinter.hx
  • Loading branch information
jdonaldson authored Apr 27, 2020
1 parent 4326802 commit b40d5ce
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 33 deletions.
13 changes: 0 additions & 13 deletions std/haxe/Resource.hx
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,10 @@ class Resource {
public static function getString(name:String):String {
for (x in content)
if (x.name == name) {
#if neko
return new String(x.data);
#else
if (x.str != null)
return x.str;
var b:haxe.io.Bytes = haxe.crypto.Base64.decode(x.data);
return b.toString();
#end
}
return null;
}
Expand All @@ -71,23 +67,14 @@ class Resource {
public static function getBytes(name:String):haxe.io.Bytes {
for (x in content)
if (x.name == name) {
#if neko
return haxe.io.Bytes.ofData(cast x.data);
#else
if (x.str != null)
return haxe.io.Bytes.ofString(x.str);
return haxe.crypto.Base64.decode(x.data);
#end
}
return null;
}

static function __init__() {
#if neko
var tmp = untyped __resources__();
content = untyped Array.new1(tmp, __dollar__asize(tmp));
#else
content = untyped __resources__();
#end
}
}
2 changes: 0 additions & 2 deletions std/haxe/Timer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ class Timer {
public static inline function stamp():Float {
#if flash
return flash.Lib.getTimer() / 1000;
#elseif (neko || php)
return Sys.time();
#elseif js
#if nodejs
var hrtime = js.Syntax.code('process.hrtime()'); // [seconds, remaining nanoseconds]
Expand Down
13 changes: 0 additions & 13 deletions std/haxe/crypto/Md5.hx
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,12 @@ package haxe.crypto;
**/
class Md5 {
public static function encode(s:String):String {
#if neko
return untyped new String(base_encode(make_md5(s.__s), "0123456789abcdef".__s));
#else
var m = new Md5();
var h = m.doEncode(str2blks(s));
return m.hex(h);
#end
}

public static function make(b:haxe.io.Bytes):haxe.io.Bytes {
#if neko
return haxe.io.Bytes.ofData(make_md5(b.getData()));
#else
var h = new Md5().doEncode(bytes2blks(b));
var out = haxe.io.Bytes.alloc(16);
var p = 0;
Expand All @@ -50,13 +43,8 @@ class Md5 {
out.set(p++, h[i] >>> 24);
}
return out;
#end
}

#if neko
static var base_encode = neko.Lib.load("std", "base_encode", 2);
static var make_md5 = neko.Lib.load("std", "make_md5", 1);
#else
/*
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
* Digest Algorithm, as defined in RFC 1321.
Expand Down Expand Up @@ -277,5 +265,4 @@ class Md5 {
}
return [a, b, c, d];
}
#end
}
5 changes: 0 additions & 5 deletions std/haxe/io/StringInput.hx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ package haxe.io;

class StringInput extends BytesInput {
public function new(s:String) {
#if neko
// don't copy the string
super(neko.Lib.bytesReference(s));
#else
super(haxe.io.Bytes.ofString(s));
#end
}
}
53 changes: 53 additions & 0 deletions std/neko/_std/haxe/Resource.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/

package haxe;

@:coreApi
class Resource {
static var content:Array<{name:String, data:String, str:String}>;

public static function listNames():Array<String> {
return [for (x in content) x.name];
}

public static function getString(name:String):String {
for (x in content)
if (x.name == name) {
return new String(x.data);
}
return null;
}

public static function getBytes(name:String):haxe.io.Bytes {
for (x in content)
if (x.name == name) {
return haxe.io.Bytes.ofData(cast x.data);
}
return null;
}

static function __init__() : Void {
var tmp = untyped __resources__();
content = untyped Array.new1(tmp, __dollar__asize(tmp));
}
}
36 changes: 36 additions & 0 deletions std/neko/_std/haxe/crypto/Md5.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/

package haxe.crypto;

class Md5 {
public static function encode(s:String):String {
return untyped new String(base_encode(make_md5(s.__s), "0123456789abcdef".__s));
}

public static function make(b:haxe.io.Bytes):haxe.io.Bytes {
return haxe.io.Bytes.ofData(make_md5(b.getData()));
}

static var base_encode = neko.Lib.load("std", "base_encode", 2);
static var make_md5 = neko.Lib.load("std", "make_md5", 1);
}
29 changes: 29 additions & 0 deletions std/neko/_std/haxe/io/StringInput.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/

package haxe.io;

class StringInput extends BytesInput {
public function new(s:String) {
super(neko.Lib.bytesReference(s));
}
}

0 comments on commit b40d5ce

Please sign in to comment.