Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.dynjs.runtime.builtins.types;
  
 
 public class BuiltinString extends AbstractBuiltinType {
 
     public BuiltinString(final GlobalContext globalContext) {
         super(globalContext"value");
 
         final DynString proto = new DynString(globalContext"");
         setPrototypeProperty(proto);
     }
 
     public void initialize(GlobalContext globalContextJSObject proto) {
         // String.foo()
         defineNonEnumerableProperty(this"fromCharCode"new FromCharCode(globalContext) );
         
         // String.prototype.foo()
         proto.setPrototype(globalContext.getPrototypeFor("Object"));
         defineNonEnumerableProperty(proto"constructor"this );
         defineNonEnumerableProperty(proto"toString"new ToString(globalContext) );
         defineNonEnumerableProperty(proto"valueOf"new ValueOf(globalContext) );
         defineNonEnumerableProperty(proto"charAt"new CharAt(globalContext) );
         defineNonEnumerableProperty(proto"charCodeAt"new CharCodeAt(globalContext) );
         defineNonEnumerableProperty(proto"concat"new Concat(globalContext) );
         defineNonEnumerableProperty(proto"indexOf"new IndexOf(globalContext) );
         defineNonEnumerableProperty(proto"lastIndexOf"new LastIndexOf(globalContext) );
         defineNonEnumerableProperty(proto"localeCompare"new LocaleCompare(globalContext) );
         defineNonEnumerableProperty(proto"match"new Match(globalContext) );
         defineNonEnumerableProperty(proto"search"new Search(globalContext) );
         defineNonEnumerableProperty(proto"slice"new Slice(globalContext) );
         defineNonEnumerableProperty(proto"split"new Split(globalContext) );
         defineNonEnumerableProperty(proto"substring"new Substring(globalContext) );
         defineNonEnumerableProperty(proto"substr"new Substr(globalContext) ); // Alias, 'cause node likes this
         defineNonEnumerableProperty(proto"toLowerCase"new ToLowerCase(globalContext) );
         defineNonEnumerableProperty(proto"toUpperCase"new ToUpperCase(globalContext) );
         defineNonEnumerableProperty(proto"toLocaleLowerCase"new ToLocaleLowerCase(globalContext) );
         defineNonEnumerableProperty(proto"toLocaleUpperCase"new ToLocaleUpperCase(globalContext) );
         defineNonEnumerableProperty(proto"trim"new Trim(globalContext) );
         defineNonEnumerableProperty(proto"replace"new Replace(globalContext) ); // http://es5.github.com/#x15.5.4.11
     }
 
     @Override
     public Object call(ExecutionContext contextObject selfObject... args) {
         Arguments argsObj = (Argumentscontext.resolve("arguments").getValue(context);
         int numArgs = (intargsObj.get(context"length");
         
         if (self != . && self != . ) {
             // Constructor
             String value = "";
             if (numArgs != 0 ) {
                 value = Types.toStringcontextargs[0] );
             }
             PrimitiveDynObject primSelf = (PrimitiveDynObjectself;
             primSelf.setPrimitiveValue(value);
             return primSelf;
         } else {
             // As function
             if ( numArgs == 0 ) {
                 return "";
             }
             return Types.toString(contextargs[0]);
         }
     }
 
     @Override
     public JSObject createNewObject(ExecutionContext context) {
         return new DynString(context.getGlobalContext());
     }
     
     @Override
     public void setFileName() {
        this. = "org/dynjs/runtime/builtins/types/BuiltinString.java";
    }
    @Override
    public void setupDebugContext() {
        this. = "<native function: String>";
    }
    
New to GrepCode? Check out our FAQ X