1 38 package com.gargoylesoftware.htmlunit.javascript.host; 39 40 import java.util.Map ; 41 42 import org.mozilla.javascript.Context; 43 import org.mozilla.javascript.Function; 44 import org.mozilla.javascript.Scriptable; 45 46 import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine; 47 import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; 48 49 58 public class ActiveXObject extends SimpleScriptable { 59 private static final long serialVersionUID = 7327032075131452226L; 60 61 64 public ActiveXObject() { 65 } 66 67 76 public static Scriptable jsConstructor( 77 final Context cx, final Object [] args, final Function ctorObj, 78 final boolean inNewExpr) { 79 if( args.length < 1 || args.length > 2 ) { 80 throw Context.reportRuntimeError( 81 "ActiveXObject Error: constructor must have one or two String parameters." ); 82 } 83 if( args[0] == Context.getUndefinedValue() ) { 84 throw Context.reportRuntimeError( "ActiveXObject Error: constructor parameter is undefined." ); 85 } 86 if( !(args[0] instanceof String ) ) { 87 throw Context.reportRuntimeError( "ActiveXObject Error: constructor parameter must be a String." ); 88 } 89 final Map map = JavaScriptEngine.getWebClientForCurrentThread().getActiveXObjectMap(); 90 if ( map == null ) { 91 throw Context.reportRuntimeError( "ActiveXObject Error: the map is null." ); 92 } 93 final Object mapValue = map.get(args[0]); 94 if( mapValue == null ) { 95 throw Context.reportRuntimeError( "ActiveXObject Error: no map for " + args[0] + "." ); 96 } 97 if( !(mapValue instanceof String ) ) { 98 throw Context.reportRuntimeError( "ActiveXObject Error: value for " + args[0] + " is not a String." ); 99 } 100 101 final String xClassString = (String )mapValue; 102 Object object = null; 103 try { 104 final Class xClass = Class.forName(xClassString); 105 object = xClass.newInstance(); 106 } 107 catch( final Exception e ) { 108 throw Context.reportRuntimeError( "ActiveXObject Error: failed instantiating class " + xClassString + 109 " because " + e.getMessage() + "." ); 110 } 111 return Context.toObject( object, ctorObj ); 112 } 113 114 118 public String getClassName() { 119 return "ActiveXObject"; 120 } 121 } 122 | Popular Tags |