6
6
using Jint . Native ;
7
7
using Jint . Native . Function ;
8
8
using Jint . Native . Object ;
9
- using Jint . Native . String ;
10
9
using Jint . Runtime ;
11
10
using Jint . Runtime . Descriptors ;
12
11
using Jint . Runtime . Interop ;
@@ -91,7 +90,7 @@ public static Object FromJsValue(this JsValue val)
91
90
var node = obj as DomNodeInstance ;
92
91
return node != null ? node . Value : obj ;
93
92
case Types . Undefined :
94
- return "undefined" ;
93
+ return Undefined . Text ;
95
94
case Types . Null :
96
95
return null ;
97
96
}
@@ -109,12 +108,38 @@ public static Object As(this Object value, Type targetType, EngineInstance engin
109
108
{
110
109
return value ;
111
110
}
112
- else if ( sourceType == typeof ( Double ) && targetType == typeof ( Int32 ) )
111
+ else if ( targetType == typeof ( Int32 ) )
113
112
{
113
+ if ( sourceType != typeof ( Double ) )
114
+ {
115
+ var v = value . ToJsValue ( engine ) ;
116
+ return TypeConverter . ToInt32 ( v ) ;
117
+ }
118
+
114
119
return ( Int32 ) ( Double ) value ;
115
120
}
121
+ else if ( targetType == typeof ( Double ) )
122
+ {
123
+ var v = value . ToJsValue ( engine ) ;
124
+ return TypeConverter . ToNumber ( v ) ;
125
+ }
126
+ else if ( targetType == typeof ( String ) )
127
+ {
128
+ var v = value . ToJsValue ( engine ) ;
116
129
117
- if ( targetType . GetTypeInfo ( ) . IsSubclassOf ( typeof ( Delegate ) ) )
130
+ if ( v . IsPrimitive ( ) )
131
+ {
132
+ return TypeConverter . ToString ( v ) ;
133
+ }
134
+
135
+ return v . ToString ( ) ;
136
+ }
137
+ else if ( targetType == typeof ( Boolean ) )
138
+ {
139
+ var v = value . ToJsValue ( engine ) ;
140
+ return TypeConverter . ToBoolean ( v ) ;
141
+ }
142
+ else if ( targetType . GetTypeInfo ( ) . IsSubclassOf ( typeof ( Delegate ) ) )
118
143
{
119
144
var f = value as FunctionInstance ;
120
145
0 commit comments