Exemplo n.º 1
0
  /**
   * Create a new instance of NativeNumber
   *
   * @param owningEnvironment The environment in which this native number was created
   */
  public JSNumberConstructor(Environment owningEnvironment) {
    super(owningEnvironment);

    int fileIndex = FileContextManager.BUILT_IN_FILE_INDEX;
    int offset = Range.Empty.getStartingOffset();

    // get global
    IScope global = owningEnvironment.getGlobal();

    // put self into environment
    global.putPropertyValue(
        "Number", this, fileIndex, Property.DONT_DELETE | Property.DONT_ENUM); // $NON-NLS-1$

    // set Number.[[prototype]]
    IObject function = global.getPropertyValue("Function", fileIndex, offset); // $NON-NLS-1$
    IObject functionPrototype =
        function.getPropertyValue("prototype", fileIndex, offset); // $NON-NLS-1$
    this.setPrototype(functionPrototype);

    // create public prototype object
    IObject prototype = owningEnvironment.createObject(fileIndex, Range.Empty);

    // store our public prototype
    this.putPropertyValue("prototype", prototype, fileIndex); // $NON-NLS-1$
  }
Exemplo n.º 2
0
  /** Initialize the properties on this object */
  public void initializeProperties() {
    Environment environment = this.owningEnvironment;
    int attributes = Property.DONT_DELETE | Property.DONT_ENUM;
    int fileIndex = FileContextManager.BUILT_IN_FILE_INDEX;
    int offset = Range.Empty.getStartingOffset();

    // add properties to Number
    this.putPropertyValue(
        "length",
        environment.createNumber(fileIndex, Range.Empty),
        fileIndex,
        attributes); //$NON-NLS-1$
    this.putPropertyValue(
        "MAX_VALUE",
        environment.createNumber(fileIndex, Range.Empty),
        fileIndex,
        attributes); //$NON-NLS-1$
    this.putPropertyValue(
        "MIN_VALUE",
        environment.createNumber(fileIndex, Range.Empty),
        fileIndex,
        attributes); //$NON-NLS-1$
    this.putPropertyValue(
        "NaN",
        environment.createNumber(fileIndex, Range.Empty),
        fileIndex,
        attributes); //$NON-NLS-1$
    this.putPropertyValue(
        "NEGATIVE_INFINITY",
        environment.createNumber(fileIndex, Range.Empty),
        fileIndex,
        attributes); //$NON-NLS-1$
    this.putPropertyValue(
        "POSITIVE_INFINITY",
        environment.createNumber(fileIndex, Range.Empty),
        fileIndex,
        attributes); //$NON-NLS-1$

    // add properties to Number.prototype
    IObject prototype = this.getPropertyValue("prototype", fileIndex, offset); // $NON-NLS-1$

    prototype.putPropertyValue("constructor", this, fileIndex, attributes); // $NON-NLS-1$
    prototype.putPropertyValue(
        "toString",
        environment.createFunction(fileIndex, Range.Empty),
        fileIndex,
        attributes); //$NON-NLS-1$
    prototype.putPropertyValue(
        "toLocaleString",
        environment.createFunction(fileIndex, Range.Empty),
        fileIndex,
        attributes); //$NON-NLS-1$
    prototype.putPropertyValue(
        "valueOf",
        environment.createFunction(fileIndex, Range.Empty),
        fileIndex,
        attributes); //$NON-NLS-1$
    prototype.putPropertyValue(
        "toFixed",
        environment.createFunction(fileIndex, Range.Empty),
        fileIndex,
        attributes); //$NON-NLS-1$
    prototype.putPropertyValue(
        "toExponential",
        environment.createFunction(fileIndex, Range.Empty),
        fileIndex,
        attributes); //$NON-NLS-1$
    prototype.putPropertyValue(
        "toPrecision",
        environment.createFunction(fileIndex, Range.Empty),
        fileIndex,
        attributes); //$NON-NLS-1$
  }