blob: 9831089b919d1c82ab97e0720448558ea6217756 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.e4.languages.javascript.rhino.jsdi;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.e4.languages.javascript.jsdi.PropertiesReference;
import org.eclipse.e4.languages.javascript.jsdi.Property;
import org.eclipse.e4.languages.javascript.jsdi.Value;
/**
* Rhino properties reference implementation
*
* @since 1.0
*/
abstract public class PropertiesReferenceImpl extends MirrorImpl implements PropertiesReference {
protected StackFrameImpl frame;
private final List properties = new ArrayList();
public PropertiesReferenceImpl(VirtualMachineImpl vm, Map body, StackFrameImpl frame) {
super(vm);
this.frame = frame;
List jsonProperties = (List) body.get("properties");
for (Iterator iterator = jsonProperties.iterator(); iterator.hasNext();) {
Map jsonProperty = (Map) iterator.next();
String name = (String) jsonProperty.get("name");
Number ref = (Number) jsonProperty.get("ref");
PropertyImpl property = new PropertyImpl(vm, name, ref);
properties.add(property);
}
}
public Value getValue(Property property) {
PropertyImpl propertyImpl = (PropertyImpl) property;
return frame.lookupValue(propertyImpl.getRef());
}
public List properties() {
return properties;
}
}