|
@@ -70,8 +70,15 @@ class Boot {
|
|
|
static inline function getClass(o:Dynamic) : Dynamic {
|
|
|
if (Std.is(o, Array))
|
|
|
return Array;
|
|
|
- else
|
|
|
- return untyped __define_feature__("js.Boot.getClass", o.__class__);
|
|
|
+ else {
|
|
|
+ var cl = untyped __define_feature__("js.Boot.getClass", o.__class__);
|
|
|
+ if (cl != null)
|
|
|
+ return cl;
|
|
|
+ var name = __nativeClassName(o);
|
|
|
+ if (name != null)
|
|
|
+ return __resolveNativeClass(name);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@:ifFeature("may_print_enum")
|
|
@@ -180,14 +187,17 @@ class Boot {
|
|
|
return true;
|
|
|
default:
|
|
|
if( o != null ) {
|
|
|
- // Check if o is an instance of a Haxe class
|
|
|
+ // Check if o is an instance of a Haxe class or a native JS object
|
|
|
if( (untyped __js__("typeof"))(cl) == "function" ) {
|
|
|
- if( untyped __js__("o instanceof cl") ) {
|
|
|
+ if( untyped __js__("o instanceof cl") )
|
|
|
return true;
|
|
|
- }
|
|
|
if( __interfLoop(getClass(o),cl) )
|
|
|
return true;
|
|
|
}
|
|
|
+ else if ( (untyped __js__("typeof"))(cl) == "object" && __isNativeObj(cl) ) {
|
|
|
+ if( untyped __js__("o instanceof cl") )
|
|
|
+ return true;
|
|
|
+ }
|
|
|
} else {
|
|
|
return false;
|
|
|
}
|
|
@@ -202,5 +212,29 @@ class Boot {
|
|
|
if (__instanceof(o, t)) return o;
|
|
|
else throw "Cannot cast " +Std.string(o) + " to " +Std.string(t);
|
|
|
}
|
|
|
+
|
|
|
+ static var __toStr = untyped __js__("{}.toString");
|
|
|
+ // get native JS [[Class]]
|
|
|
+ static function __nativeClassName(o:Dynamic):String {
|
|
|
+ var name = untyped __toStr.call(o).slice(8, -1);
|
|
|
+ // exclude general Object and Function
|
|
|
+ // also exclude Math and JSON, because instanceof cannot be called on them
|
|
|
+ if (name == "Object" || name == "Function" || name == "Math" || name == "JSON")
|
|
|
+ return null;
|
|
|
+ return name;
|
|
|
+ }
|
|
|
+
|
|
|
+ // check for usable native JS object
|
|
|
+ static function __isNativeObj(o:Dynamic):Bool {
|
|
|
+ return __nativeClassName(o) != null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // resolve native JS class (with window or global):
|
|
|
+ static function __resolveNativeClass(name:String) untyped {
|
|
|
+ if (__js__("typeof window") != "undefined")
|
|
|
+ return window[name];
|
|
|
+ else
|
|
|
+ return global[name];
|
|
|
+ }
|
|
|
|
|
|
}
|