source: webkit/trunk/Source/JavaScriptCore/jsc.cpp@ 116828

Last change on this file since 116828 was 116828, checked in by [email protected], 13 years ago

Introduce PropertyName class
https://bugs.webkit.org/show_bug.cgi?id=86241

Reviewed by Geoff Garen.

Replace 'const Identifier&' arguments to functions accessing object properties with a new 'PropertyName' type.
This change paves the way to allow for properties keyed by values that are not Identifiers.

This change is largely a mechanical find & replace.
It also changes JSFunction's constructor to take a UString& instead of an Identifier&
(since in some cases we can no longer guarantee that we'lll have an Identifier), and
unifies Identifier's methods to obtain array indices onto PropertyName.

The new PropertyName class retains the ability to support .impl() and .ustring(), but
in a future patch we may need to rework this, since not all PropertyNames should be
equal based on their string representation.

Source/JavaScriptCore:

  • API/JSCallbackFunction.cpp:

(JSC::JSCallbackFunction::finishCreation):

  • API/JSCallbackFunction.h:

(JSCallbackFunction):
(JSC::JSCallbackFunction::create):

  • API/JSCallbackObject.h:

(JSCallbackObject):

  • API/JSCallbackObjectFunctions.h:

(JSC::::getOwnPropertySlot):
(JSC::::getOwnPropertyDescriptor):
(JSC::::put):
(JSC::::deleteProperty):
(JSC::::getStaticValue):
(JSC::::staticFunctionGetter):
(JSC::::callbackGetter):

  • API/JSObjectRef.cpp:

(JSObjectMakeFunctionWithCallback):

  • JSCTypedArrayStubs.h:

(JSC):

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • debugger/DebuggerActivation.cpp:

(JSC::DebuggerActivation::getOwnPropertySlot):
(JSC::DebuggerActivation::put):
(JSC::DebuggerActivation::putDirectVirtual):
(JSC::DebuggerActivation::deleteProperty):
(JSC::DebuggerActivation::getOwnPropertyDescriptor):
(JSC::DebuggerActivation::defineOwnProperty):

  • debugger/DebuggerActivation.h:

(DebuggerActivation):

  • jsc.cpp:

(GlobalObject::addFunction):
(GlobalObject::addConstructableFunction):

  • runtime/Arguments.cpp:

(JSC::Arguments::getOwnPropertySlot):
(JSC::Arguments::getOwnPropertyDescriptor):
(JSC::Arguments::put):
(JSC::Arguments::deleteProperty):
(JSC::Arguments::defineOwnProperty):

  • runtime/Arguments.h:

(Arguments):

  • runtime/ArrayConstructor.cpp:

(JSC::ArrayConstructor::finishCreation):
(JSC::ArrayConstructor::getOwnPropertySlot):
(JSC::ArrayConstructor::getOwnPropertyDescriptor):

  • runtime/ArrayConstructor.h:

(ArrayConstructor):

  • runtime/ArrayPrototype.cpp:

(JSC::ArrayPrototype::getOwnPropertySlot):
(JSC::ArrayPrototype::getOwnPropertyDescriptor):
(JSC::putProperty):

  • runtime/ArrayPrototype.h:

(ArrayPrototype):

  • runtime/BooleanConstructor.cpp:

(JSC::BooleanConstructor::finishCreation):

  • runtime/BooleanPrototype.cpp:

(JSC::BooleanPrototype::getOwnPropertySlot):
(JSC::BooleanPrototype::getOwnPropertyDescriptor):

  • runtime/BooleanPrototype.h:

(BooleanPrototype):

  • runtime/ClassInfo.h:

(MethodTable):

  • runtime/DateConstructor.cpp:

(JSC::DateConstructor::finishCreation):
(JSC::DateConstructor::getOwnPropertySlot):
(JSC::DateConstructor::getOwnPropertyDescriptor):

  • runtime/DateConstructor.h:

(DateConstructor):

  • runtime/DatePrototype.cpp:

(JSC::DatePrototype::getOwnPropertySlot):
(JSC::DatePrototype::getOwnPropertyDescriptor):

  • runtime/DatePrototype.h:

(DatePrototype):

  • runtime/Error.h:

(JSC::StrictModeTypeErrorFunction::create):

  • runtime/ErrorConstructor.cpp:

(JSC::ErrorConstructor::finishCreation):

  • runtime/ErrorPrototype.cpp:

(JSC::ErrorPrototype::getOwnPropertySlot):
(JSC::ErrorPrototype::getOwnPropertyDescriptor):

  • runtime/ErrorPrototype.h:

(ErrorPrototype):

  • runtime/FunctionConstructor.cpp:

(JSC::FunctionConstructor::finishCreation):

  • runtime/FunctionPrototype.cpp:

(JSC::FunctionPrototype::finishCreation):
(JSC::FunctionPrototype::addFunctionProperties):
(JSC::functionProtoFuncBind):

  • runtime/FunctionPrototype.h:

(JSC::FunctionPrototype::create):
(FunctionPrototype):

  • runtime/Identifier.cpp:

(JSC):

  • runtime/Identifier.h:

(Identifier):

  • runtime/InternalFunction.cpp:

(JSC::InternalFunction::finishCreation):

  • runtime/InternalFunction.h:

(InternalFunction):

  • runtime/JSActivation.cpp:

(JSC::JSActivation::symbolTableGet):
(JSC::JSActivation::symbolTablePut):
(JSC::JSActivation::symbolTablePutWithAttributes):
(JSC::JSActivation::getOwnPropertySlot):
(JSC::JSActivation::put):
(JSC::JSActivation::putDirectVirtual):
(JSC::JSActivation::deleteProperty):
(JSC::JSActivation::argumentsGetter):

  • runtime/JSActivation.h:

(JSActivation):

  • runtime/JSArray.cpp:

(JSC::JSArray::defineOwnProperty):
(JSC::JSArray::getOwnPropertySlot):
(JSC::JSArray::getOwnPropertyDescriptor):
(JSC::JSArray::put):
(JSC::JSArray::deleteProperty):

  • runtime/JSArray.h:

(JSArray):
(JSC):

  • runtime/JSBoundFunction.cpp:

(JSC::JSBoundFunction::create):
(JSC::JSBoundFunction::finishCreation):

  • runtime/JSBoundFunction.h:

(JSBoundFunction):

  • runtime/JSCell.cpp:

(JSC::JSCell::getOwnPropertySlot):
(JSC::JSCell::put):
(JSC::JSCell::deleteProperty):
(JSC::JSCell::putDirectVirtual):
(JSC::JSCell::defineOwnProperty):
(JSC::JSCell::getOwnPropertyDescriptor):

  • runtime/JSCell.h:

(JSCell):

  • runtime/JSFunction.cpp:

(JSC::JSFunction::create):
(JSC::JSFunction::finishCreation):
(JSC::JSFunction::argumentsGetter):
(JSC::JSFunction::callerGetter):
(JSC::JSFunction::lengthGetter):
(JSC::JSFunction::getOwnPropertySlot):
(JSC::JSFunction::getOwnPropertyDescriptor):
(JSC::JSFunction::put):
(JSC::JSFunction::deleteProperty):
(JSC::JSFunction::defineOwnProperty):
(JSC::getCalculatedDisplayName):

  • runtime/JSFunction.h:

(JSFunction):

  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::put):
(JSC::JSGlobalObject::putDirectVirtual):
(JSC::JSGlobalObject::defineOwnProperty):
(JSC::JSGlobalObject::reset):
(JSC::JSGlobalObject::createThrowTypeError):
(JSC::JSGlobalObject::getOwnPropertySlot):
(JSC::JSGlobalObject::getOwnPropertyDescriptor):

  • runtime/JSGlobalObject.h:

(JSGlobalObject):
(JSC::JSGlobalObject::hasOwnPropertyForWrite):
(JSC::JSGlobalObject::symbolTableHasProperty):

  • runtime/JSNotAnObject.cpp:

(JSC::JSNotAnObject::getOwnPropertySlot):
(JSC::JSNotAnObject::getOwnPropertyDescriptor):
(JSC::JSNotAnObject::put):
(JSC::JSNotAnObject::deleteProperty):

  • runtime/JSNotAnObject.h:

(JSNotAnObject):

  • runtime/JSONObject.cpp:

(JSC::JSONObject::getOwnPropertySlot):
(JSC::JSONObject::getOwnPropertyDescriptor):

  • runtime/JSONObject.h:

(JSONObject):

  • runtime/JSObject.cpp:

(JSC::JSObject::put):
(JSC::JSObject::putDirectVirtual):
(JSC::JSObject::putDirectAccessor):
(JSC::JSObject::hasProperty):
(JSC::JSObject::deleteProperty):
(JSC::JSObject::hasOwnProperty):
(JSC::callDefaultValueFunction):
(JSC::JSObject::findPropertyHashEntry):
(JSC::JSObject::getPropertySpecificValue):
(JSC::JSObject::removeDirect):
(JSC::JSObject::getOwnPropertyDescriptor):
(JSC::JSObject::getPropertyDescriptor):
(JSC::putDescriptor):
(JSC::JSObject::defineOwnProperty):

  • runtime/JSObject.h:

(JSObject):
(JSC::JSObject::getDirect):
(JSC::JSObject::getDirectLocation):
(JSC::JSObject::inlineGetOwnPropertySlot):
(JSC::JSObject::getOwnPropertySlot):
(JSC::JSCell::fastGetOwnPropertySlot):
(JSC::JSObject::getPropertySlot):
(JSC::JSObject::get):
(JSC::JSObject::putDirectInternal):
(JSC::JSObject::putOwnDataProperty):
(JSC::JSObject::putDirect):
(JSC::JSObject::putDirectWithoutTransition):
(JSC::JSValue::get):
(JSC::JSValue::put):

  • runtime/JSStaticScopeObject.cpp:

(JSC::JSStaticScopeObject::put):
(JSC::JSStaticScopeObject::putDirectVirtual):
(JSC::JSStaticScopeObject::getOwnPropertySlot):

  • runtime/JSStaticScopeObject.h:

(JSStaticScopeObject):

  • runtime/JSString.cpp:

(JSC::JSString::getOwnPropertySlot):
(JSC::JSString::getStringPropertyDescriptor):

  • runtime/JSString.h:

(JSString):
(JSC::JSString::getStringPropertySlot):

  • runtime/JSValue.cpp:

(JSC::JSValue::putToPrimitive):

  • runtime/JSValue.h:

(JSC):
(JSValue):

  • runtime/JSVariableObject.cpp:

(JSC::JSVariableObject::deleteProperty):
(JSC::JSVariableObject::symbolTableGet):
(JSC::JSVariableObject::putDirectVirtual):

  • runtime/JSVariableObject.h:

(JSVariableObject):
(JSC::JSVariableObject::symbolTableGet):
(JSC::JSVariableObject::symbolTablePut):
(JSC::JSVariableObject::symbolTablePutWithAttributes):

  • runtime/Lookup.cpp:

(JSC::setUpStaticFunctionSlot):

  • runtime/Lookup.h:

(JSC::HashTable::entry):
(JSC):
(JSC::getStaticPropertySlot):
(JSC::getStaticPropertyDescriptor):
(JSC::getStaticFunctionSlot):
(JSC::getStaticFunctionDescriptor):
(JSC::getStaticValueSlot):
(JSC::getStaticValueDescriptor):
(JSC::lookupPut):

  • runtime/MathObject.cpp:

(JSC::MathObject::getOwnPropertySlot):
(JSC::MathObject::getOwnPropertyDescriptor):

  • runtime/MathObject.h:

(MathObject):

  • runtime/NativeErrorConstructor.h:

(JSC::NativeErrorConstructor::finishCreation):

  • runtime/NumberConstructor.cpp:

(JSC):
(JSC::NumberConstructor::finishCreation):
(JSC::NumberConstructor::getOwnPropertySlot):
(JSC::NumberConstructor::getOwnPropertyDescriptor):
(JSC::NumberConstructor::put):
(JSC::numberConstructorNaNValue):
(JSC::numberConstructorNegInfinity):
(JSC::numberConstructorPosInfinity):
(JSC::numberConstructorMaxValue):
(JSC::numberConstructorMinValue):

  • runtime/NumberConstructor.h:

(NumberConstructor):

  • runtime/NumberPrototype.cpp:

(JSC::NumberPrototype::getOwnPropertySlot):
(JSC::NumberPrototype::getOwnPropertyDescriptor):

  • runtime/NumberPrototype.h:

(NumberPrototype):

  • runtime/ObjectConstructor.cpp:

(JSC::ObjectConstructor::finishCreation):
(JSC::ObjectConstructor::getOwnPropertySlot):
(JSC::ObjectConstructor::getOwnPropertyDescriptor):

  • runtime/ObjectConstructor.h:

(ObjectConstructor):

  • runtime/ObjectPrototype.cpp:

(JSC::ObjectPrototype::put):
(JSC::ObjectPrototype::defineOwnProperty):
(JSC::ObjectPrototype::getOwnPropertySlot):
(JSC::ObjectPrototype::getOwnPropertyDescriptor):

  • runtime/ObjectPrototype.h:

(ObjectPrototype):

  • runtime/PropertySlot.h:

(PropertySlot):
(JSC::PropertySlot::getValue):

  • runtime/RegExpConstructor.cpp:

(JSC):
(JSC::RegExpConstructor::finishCreation):
(JSC::RegExpConstructor::getOwnPropertySlot):
(JSC::RegExpConstructor::getOwnPropertyDescriptor):
(JSC::regExpConstructorDollar1):
(JSC::regExpConstructorDollar2):
(JSC::regExpConstructorDollar3):
(JSC::regExpConstructorDollar4):
(JSC::regExpConstructorDollar5):
(JSC::regExpConstructorDollar6):
(JSC::regExpConstructorDollar7):
(JSC::regExpConstructorDollar8):
(JSC::regExpConstructorDollar9):
(JSC::regExpConstructorInput):
(JSC::regExpConstructorMultiline):
(JSC::regExpConstructorLastMatch):
(JSC::regExpConstructorLastParen):
(JSC::regExpConstructorLeftContext):
(JSC::regExpConstructorRightContext):
(JSC::RegExpConstructor::put):

  • runtime/RegExpConstructor.h:

(RegExpConstructor):

  • runtime/RegExpMatchesArray.h:

(JSC::RegExpMatchesArray::getOwnPropertySlot):
(JSC::RegExpMatchesArray::getOwnPropertyDescriptor):
(JSC::RegExpMatchesArray::put):
(JSC::RegExpMatchesArray::deleteProperty):
(JSC::RegExpMatchesArray::defineOwnProperty):

  • runtime/RegExpObject.cpp:

(JSC):
(JSC::RegExpObject::getOwnPropertySlot):
(JSC::RegExpObject::getOwnPropertyDescriptor):
(JSC::RegExpObject::deleteProperty):
(JSC::RegExpObject::defineOwnProperty):
(JSC::regExpObjectGlobal):
(JSC::regExpObjectIgnoreCase):
(JSC::regExpObjectMultiline):
(JSC::regExpObjectSource):
(JSC::RegExpObject::put):

  • runtime/RegExpObject.h:

(RegExpObject):

  • runtime/RegExpPrototype.cpp:

(JSC::RegExpPrototype::getOwnPropertySlot):
(JSC::RegExpPrototype::getOwnPropertyDescriptor):

  • runtime/RegExpPrototype.h:

(RegExpPrototype):

  • runtime/StrictEvalActivation.cpp:

(JSC::StrictEvalActivation::deleteProperty):

  • runtime/StrictEvalActivation.h:

(StrictEvalActivation):

  • runtime/StringConstructor.cpp:

(JSC::StringConstructor::finishCreation):
(JSC::StringConstructor::getOwnPropertySlot):
(JSC::StringConstructor::getOwnPropertyDescriptor):

  • runtime/StringConstructor.h:

(StringConstructor):

  • runtime/StringObject.cpp:

(JSC::StringObject::getOwnPropertySlot):
(JSC::StringObject::getOwnPropertyDescriptor):
(JSC::StringObject::put):
(JSC::StringObject::defineOwnProperty):
(JSC::StringObject::deleteProperty):

  • runtime/StringObject.h:

(StringObject):

  • runtime/StringPrototype.cpp:

(JSC::StringPrototype::getOwnPropertySlot):
(JSC::StringPrototype::getOwnPropertyDescriptor):

  • runtime/StringPrototype.h:

(StringPrototype):

  • runtime/Structure.cpp:

(JSC::Structure::despecifyDictionaryFunction):
(JSC::Structure::addPropertyTransitionToExistingStructure):
(JSC::Structure::addPropertyTransition):
(JSC::Structure::removePropertyTransition):
(JSC::Structure::despecifyFunctionTransition):
(JSC::Structure::attributeChangeTransition):
(JSC::Structure::addPropertyWithoutTransition):
(JSC::Structure::removePropertyWithoutTransition):
(JSC::Structure::get):
(JSC::Structure::despecifyFunction):
(JSC::Structure::putSpecificValue):
(JSC::Structure::remove):

  • runtime/Structure.h:

(Structure):
(JSC::Structure::get):

Source/WebCore:

  • WebCore.exp.in:
  • bindings/js/JSCSSStyleDeclarationCustom.cpp:

(WebCore::cssPropertyIDForJSCSSPropertyName):
(WebCore::JSCSSStyleDeclaration::getOwnPropertySlotDelegate):
(WebCore::JSCSSStyleDeclaration::getOwnPropertyDescriptorDelegate):
(WebCore::JSCSSStyleDeclaration::putDelegate):

  • bindings/js/JSDOMBinding.cpp:

(WebCore::findAtomicString):
(WebCore::objectToStringFunctionGetter):

  • bindings/js/JSDOMBinding.h:

(WebCore):
(WebCore::propertyNameToString):
(WebCore::propertyNameToAtomicString):

  • bindings/js/JSDOMMimeTypeArrayCustom.cpp:

(WebCore::JSDOMMimeTypeArray::canGetItemsForName):
(WebCore::JSDOMMimeTypeArray::nameGetter):

  • bindings/js/JSDOMPluginArrayCustom.cpp:

(WebCore::JSDOMPluginArray::canGetItemsForName):
(WebCore::JSDOMPluginArray::nameGetter):

  • bindings/js/JSDOMPluginCustom.cpp:

(WebCore::JSDOMPlugin::canGetItemsForName):
(WebCore::JSDOMPlugin::nameGetter):

  • bindings/js/JSDOMStringMapCustom.cpp:

(WebCore::JSDOMStringMap::canGetItemsForName):
(WebCore::JSDOMStringMap::nameGetter):
(WebCore::JSDOMStringMap::deleteProperty):
(WebCore::JSDOMStringMap::putDelegate):

  • bindings/js/JSDOMWindowCustom.cpp:

(WebCore::nonCachingStaticFunctionGetter):
(WebCore::childFrameGetter):
(WebCore::namedItemGetter):
(WebCore::JSDOMWindow::getOwnPropertySlot):
(WebCore::JSDOMWindow::getOwnPropertyDescriptor):
(WebCore::JSDOMWindow::put):
(WebCore::JSDOMWindow::deleteProperty):
(WebCore::JSDOMWindow::defineOwnProperty):

  • bindings/js/JSDOMWindowShell.cpp:

(WebCore::JSDOMWindowShell::getOwnPropertySlot):
(WebCore::JSDOMWindowShell::getOwnPropertyDescriptor):
(WebCore::JSDOMWindowShell::put):
(WebCore::JSDOMWindowShell::putDirectVirtual):
(WebCore::JSDOMWindowShell::defineOwnProperty):
(WebCore::JSDOMWindowShell::deleteProperty):

  • bindings/js/JSDOMWindowShell.h:

(JSDOMWindowShell):

  • bindings/js/JSHTMLAllCollectionCustom.cpp:

(WebCore::getNamedItems):
(WebCore::callHTMLAllCollection):
(WebCore::JSHTMLAllCollection::canGetItemsForName):
(WebCore::JSHTMLAllCollection::nameGetter):
(WebCore::JSHTMLAllCollection::item):

  • bindings/js/JSHTMLAppletElementCustom.cpp:

(WebCore::JSHTMLAppletElement::getOwnPropertySlotDelegate):
(WebCore::JSHTMLAppletElement::getOwnPropertyDescriptorDelegate):
(WebCore::JSHTMLAppletElement::putDelegate):

  • bindings/js/JSHTMLCollectionCustom.cpp:

(WebCore::getNamedItems):
(WebCore::JSHTMLCollection::canGetItemsForName):
(WebCore::JSHTMLCollection::nameGetter):

  • bindings/js/JSHTMLDocumentCustom.cpp:

(WebCore::JSHTMLDocument::canGetItemsForName):
(WebCore::JSHTMLDocument::nameGetter):

  • bindings/js/JSHTMLEmbedElementCustom.cpp:

(WebCore::JSHTMLEmbedElement::getOwnPropertySlotDelegate):
(WebCore::JSHTMLEmbedElement::getOwnPropertyDescriptorDelegate):
(WebCore::JSHTMLEmbedElement::putDelegate):

  • bindings/js/JSHTMLFormElementCustom.cpp:

(WebCore::JSHTMLFormElement::canGetItemsForName):
(WebCore::JSHTMLFormElement::nameGetter):

  • bindings/js/JSHTMLFrameSetElementCustom.cpp:

(WebCore::JSHTMLFrameSetElement::canGetItemsForName):
(WebCore::JSHTMLFrameSetElement::nameGetter):

  • bindings/js/JSHTMLObjectElementCustom.cpp:

(WebCore::JSHTMLObjectElement::getOwnPropertySlotDelegate):
(WebCore::JSHTMLObjectElement::getOwnPropertyDescriptorDelegate):
(WebCore::JSHTMLObjectElement::putDelegate):

  • bindings/js/JSHistoryCustom.cpp:

(WebCore::nonCachingStaticBackFunctionGetter):
(WebCore::nonCachingStaticForwardFunctionGetter):
(WebCore::nonCachingStaticGoFunctionGetter):
(WebCore::JSHistory::getOwnPropertySlotDelegate):
(WebCore::JSHistory::getOwnPropertyDescriptorDelegate):
(WebCore::JSHistory::putDelegate):
(WebCore::JSHistory::deleteProperty):

  • bindings/js/JSLocationCustom.cpp:

(WebCore::nonCachingStaticReplaceFunctionGetter):
(WebCore::nonCachingStaticReloadFunctionGetter):
(WebCore::nonCachingStaticAssignFunctionGetter):
(WebCore::JSLocation::getOwnPropertySlotDelegate):
(WebCore::JSLocation::getOwnPropertyDescriptorDelegate):
(WebCore::JSLocation::putDelegate):
(WebCore::JSLocation::deleteProperty):
(WebCore::JSLocation::defineOwnProperty):
(WebCore::JSLocationPrototype::putDelegate):
(WebCore::JSLocationPrototype::defineOwnProperty):

  • bindings/js/JSNamedNodeMapCustom.cpp:

(WebCore::JSNamedNodeMap::canGetItemsForName):
(WebCore::JSNamedNodeMap::nameGetter):

  • bindings/js/JSNodeListCustom.cpp:

(WebCore::JSNodeList::canGetItemsForName):
(WebCore::JSNodeList::nameGetter):

  • bindings/js/JSPluginElementFunctions.cpp:

(WebCore::runtimeObjectPropertyGetter):
(WebCore::runtimeObjectCustomGetOwnPropertySlot):
(WebCore::runtimeObjectCustomGetOwnPropertyDescriptor):
(WebCore::runtimeObjectCustomPut):

  • bindings/js/JSPluginElementFunctions.h:

(WebCore):

  • bindings/js/JSStorageCustom.cpp:

(WebCore::JSStorage::canGetItemsForName):
(WebCore::JSStorage::nameGetter):
(WebCore::JSStorage::deleteProperty):
(WebCore::JSStorage::putDelegate):

  • bindings/js/JSStyleSheetListCustom.cpp:

(WebCore::JSStyleSheetList::canGetItemsForName):
(WebCore::JSStyleSheetList::nameGetter):

  • bindings/js/JSWorkerContextCustom.cpp:

(WebCore::JSWorkerContext::getOwnPropertySlotDelegate):
(WebCore::JSWorkerContext::getOwnPropertyDescriptorDelegate):

  • bindings/scripts/CodeGeneratorJS.pm:

(GenerateGetOwnPropertySlotBody):
(GenerateGetOwnPropertyDescriptorBody):
(GenerateHeader):
(GenerateImplementation):
(GenerateConstructorDeclaration):
(GenerateConstructorDefinition):

  • bridge/c/c_class.cpp:

(JSC::Bindings::CClass::methodsNamed):
(JSC::Bindings::CClass::fieldNamed):

  • bridge/c/c_class.h:

(CClass):

  • bridge/c/c_instance.cpp:

(JSC::Bindings::CRuntimeMethod::create):
(JSC::Bindings::CRuntimeMethod::finishCreation):
(JSC::Bindings::CInstance::getMethod):

  • bridge/c/c_instance.h:

(CInstance):

  • bridge/jni/jsc/JavaClassJSC.cpp:

(JavaClass::methodsNamed):
(JavaClass::fieldNamed):

  • bridge/jni/jsc/JavaClassJSC.h:

(JavaClass):

  • bridge/jni/jsc/JavaInstanceJSC.cpp:

(JavaRuntimeMethod::create):
(JavaRuntimeMethod::finishCreation):

  • bridge/jni/jsc/JavaInstanceJSC.h:

(JavaInstance):

  • bridge/jsc/BridgeJSC.h:

(Class):
(JSC::Bindings::Class::fallbackObject):
(JSC::Bindings::Instance::setValueOfUndefinedField):
(Instance):
(JSC::Bindings::Instance::getOwnPropertySlot):
(JSC::Bindings::Instance::getOwnPropertyDescriptor):
(JSC::Bindings::Instance::put):

  • bridge/objc/objc_class.h:

(ObjcClass):

  • bridge/objc/objc_class.mm:

(JSC::Bindings::ObjcClass::methodsNamed):
(JSC::Bindings::ObjcClass::fieldNamed):
(JSC::Bindings::ObjcClass::fallbackObject):

  • bridge/objc/objc_instance.h:

(ObjcInstance):

  • bridge/objc/objc_instance.mm:

(ObjCRuntimeMethod::create):
(ObjCRuntimeMethod::finishCreation):
(ObjcInstance::setValueOfUndefinedField):
(ObjcInstance::getValueOfUndefinedField):

  • bridge/objc/objc_runtime.h:

(JSC::Bindings::ObjcFallbackObjectImp::create):
(JSC::Bindings::ObjcFallbackObjectImp::propertyName):
(ObjcFallbackObjectImp):

  • bridge/objc/objc_runtime.mm:

(JSC::Bindings::ObjcFallbackObjectImp::ObjcFallbackObjectImp):
(JSC::Bindings::ObjcFallbackObjectImp::getOwnPropertySlot):
(JSC::Bindings::ObjcFallbackObjectImp::getOwnPropertyDescriptor):
(JSC::Bindings::ObjcFallbackObjectImp::put):
(JSC::Bindings::callObjCFallbackObject):
(JSC::Bindings::ObjcFallbackObjectImp::deleteProperty):
(JSC::Bindings::ObjcFallbackObjectImp::defaultValue):

  • bridge/runtime_array.cpp:

(JSC::RuntimeArray::lengthGetter):
(JSC::RuntimeArray::getOwnPropertySlot):
(JSC::RuntimeArray::getOwnPropertyDescriptor):
(JSC::RuntimeArray::put):
(JSC::RuntimeArray::deleteProperty):

  • bridge/runtime_array.h:

(RuntimeArray):

  • bridge/runtime_method.cpp:

(JSC::RuntimeMethod::finishCreation):
(JSC::RuntimeMethod::lengthGetter):
(JSC::RuntimeMethod::getOwnPropertySlot):
(JSC::RuntimeMethod::getOwnPropertyDescriptor):

  • bridge/runtime_method.h:

(JSC::RuntimeMethod::create):
(RuntimeMethod):

  • bridge/runtime_object.cpp:

(JSC::Bindings::RuntimeObject::fallbackObjectGetter):
(JSC::Bindings::RuntimeObject::fieldGetter):
(JSC::Bindings::RuntimeObject::methodGetter):
(JSC::Bindings::RuntimeObject::getOwnPropertySlot):
(JSC::Bindings::RuntimeObject::getOwnPropertyDescriptor):
(JSC::Bindings::RuntimeObject::put):
(JSC::Bindings::RuntimeObject::deleteProperty):

  • bridge/runtime_object.h:

(RuntimeObject):

Source/WebKit/mac:

  • Plugins/Hosted/ProxyInstance.h:

(ProxyInstance):

  • Plugins/Hosted/ProxyInstance.mm:

(ProxyClass):
(WebKit::ProxyClass::methodsNamed):
(WebKit::ProxyClass::fieldNamed):
(WebKit::ProxyRuntimeMethod::create):
(WebKit::ProxyRuntimeMethod::finishCreation):
(WebKit::ProxyInstance::getMethod):
(WebKit::ProxyInstance::methodsNamed):
(WebKit::ProxyInstance::fieldNamed):

Source/WebKit2:

  • WebProcess/Plugins/Netscape/JSNPMethod.cpp:

(WebKit::JSNPMethod::finishCreation):

  • WebProcess/Plugins/Netscape/JSNPMethod.h:

(WebKit::JSNPMethod::create):
(JSNPMethod):

  • WebProcess/Plugins/Netscape/JSNPObject.cpp:

(WebKit::npIdentifierFromIdentifier):
(WebKit::JSNPObject::getOwnPropertySlot):
(WebKit::JSNPObject::getOwnPropertyDescriptor):
(WebKit::JSNPObject::put):
(WebKit::JSNPObject::deleteProperty):
(WebKit::JSNPObject::propertyGetter):
(WebKit::JSNPObject::methodGetter):

  • WebProcess/Plugins/Netscape/JSNPObject.h:

(JSNPObject):

  • Property svn:eol-style set to native
File size: 22.8 KB
Line 
1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * Copyright (C) 2006 Bjoern Graf ([email protected])
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#include "config.h"
24
25#include "BytecodeGenerator.h"
26#include "Completion.h"
27#include <wtf/CurrentTime.h>
28#include "ExceptionHelpers.h"
29#include "InitializeThreading.h"
30#include "Interpreter.h"
31#include "JSArray.h"
32#include "JSCTypedArrayStubs.h"
33#include "JSFunction.h"
34#include "JSLock.h"
35#include "JSString.h"
36#include <wtf/MainThread.h>
37#include "SamplingTool.h"
38#include <math.h>
39#include <stdio.h>
40#include <stdlib.h>
41#include <string.h>
42
43#if !OS(WINDOWS)
44#include <unistd.h>
45#endif
46
47#if HAVE(READLINE)
48// readline/history.h has a Function typedef which conflicts with the WTF::Function template from WTF/Forward.h
49// We #define it to something else to avoid this conflict.
50#define Function ReadlineFunction
51#include <readline/history.h>
52#include <readline/readline.h>
53#undef Function
54#endif
55
56#if HAVE(SYS_TIME_H)
57#include <sys/time.h>
58#endif
59
60#if HAVE(SIGNAL_H)
61#include <signal.h>
62#endif
63
64#if COMPILER(MSVC) && !OS(WINCE)
65#include <crtdbg.h>
66#include <mmsystem.h>
67#include <windows.h>
68#endif
69
70#if PLATFORM(QT)
71#include <QCoreApplication>
72#include <QDateTime>
73#endif
74
75#if PLATFORM(IOS)
76#include <fenv.h>
77#include <arm/arch.h>
78#endif
79
80using namespace JSC;
81using namespace WTF;
82
83static bool fillBufferWithContentsOfFile(const UString& fileName, Vector<char>& buffer);
84
85static EncodedJSValue JSC_HOST_CALL functionPrint(ExecState*);
86static EncodedJSValue JSC_HOST_CALL functionDebug(ExecState*);
87static EncodedJSValue JSC_HOST_CALL functionJSCStack(ExecState*);
88static EncodedJSValue JSC_HOST_CALL functionGC(ExecState*);
89#ifndef NDEBUG
90static EncodedJSValue JSC_HOST_CALL functionReleaseExecutableMemory(ExecState*);
91#endif
92static EncodedJSValue JSC_HOST_CALL functionVersion(ExecState*);
93static EncodedJSValue JSC_HOST_CALL functionRun(ExecState*);
94static EncodedJSValue JSC_HOST_CALL functionLoad(ExecState*);
95static EncodedJSValue JSC_HOST_CALL functionCheckSyntax(ExecState*);
96static EncodedJSValue JSC_HOST_CALL functionReadline(ExecState*);
97static EncodedJSValue JSC_HOST_CALL functionPreciseTime(ExecState*);
98static NO_RETURN_WITH_VALUE EncodedJSValue JSC_HOST_CALL functionQuit(ExecState*);
99
100#if ENABLE(SAMPLING_FLAGS)
101static EncodedJSValue JSC_HOST_CALL functionSetSamplingFlags(ExecState*);
102static EncodedJSValue JSC_HOST_CALL functionClearSamplingFlags(ExecState*);
103#endif
104
105struct Script {
106 bool isFile;
107 char* argument;
108
109 Script(bool isFile, char *argument)
110 : isFile(isFile)
111 , argument(argument)
112 {
113 }
114};
115
116struct CommandLine {
117 CommandLine()
118 : interactive(false)
119 , dump(false)
120 {
121 }
122
123 bool interactive;
124 bool dump;
125 Vector<Script> scripts;
126 Vector<UString> arguments;
127};
128
129static const char interactivePrompt[] = "> ";
130
131class StopWatch {
132public:
133 void start();
134 void stop();
135 long getElapsedMS(); // call stop() first
136
137private:
138 double m_startTime;
139 double m_stopTime;
140};
141
142void StopWatch::start()
143{
144 m_startTime = currentTime();
145}
146
147void StopWatch::stop()
148{
149 m_stopTime = currentTime();
150}
151
152long StopWatch::getElapsedMS()
153{
154 return static_cast<long>((m_stopTime - m_startTime) * 1000);
155}
156
157class GlobalObject : public JSGlobalObject {
158private:
159 GlobalObject(JSGlobalData&, Structure*);
160
161public:
162 typedef JSGlobalObject Base;
163
164 static GlobalObject* create(JSGlobalData& globalData, Structure* structure, const Vector<UString>& arguments)
165 {
166 GlobalObject* object = new (NotNull, allocateCell<GlobalObject>(globalData.heap)) GlobalObject(globalData, structure);
167 object->finishCreation(globalData, arguments);
168 return object;
169 }
170
171 static const ClassInfo s_info;
172
173 static Structure* createStructure(JSGlobalData& globalData, JSValue prototype)
174 {
175 return Structure::create(globalData, 0, prototype, TypeInfo(GlobalObjectType, StructureFlags), &s_info);
176 }
177
178protected:
179 void finishCreation(JSGlobalData& globalData, const Vector<UString>& arguments)
180 {
181 Base::finishCreation(globalData);
182
183 addFunction(globalData, "debug", functionDebug, 1);
184 addFunction(globalData, "print", functionPrint, 1);
185 addFunction(globalData, "quit", functionQuit, 0);
186 addFunction(globalData, "gc", functionGC, 0);
187#ifndef NDEBUG
188 addFunction(globalData, "releaseExecutableMemory", functionReleaseExecutableMemory, 0);
189#endif
190 addFunction(globalData, "version", functionVersion, 1);
191 addFunction(globalData, "run", functionRun, 1);
192 addFunction(globalData, "load", functionLoad, 1);
193 addFunction(globalData, "checkSyntax", functionCheckSyntax, 1);
194 addFunction(globalData, "jscStack", functionJSCStack, 1);
195 addFunction(globalData, "readline", functionReadline, 0);
196 addFunction(globalData, "preciseTime", functionPreciseTime, 0);
197#if ENABLE(SAMPLING_FLAGS)
198 addFunction(globalData, "setSamplingFlags", functionSetSamplingFlags, 1);
199 addFunction(globalData, "clearSamplingFlags", functionClearSamplingFlags, 1);
200#endif
201
202 addConstructableFunction(globalData, "Uint8Array", constructJSUint8Array, 1);
203 addConstructableFunction(globalData, "Uint8ClampedArray", constructJSUint8ClampedArray, 1);
204 addConstructableFunction(globalData, "Uint16Array", constructJSUint16Array, 1);
205 addConstructableFunction(globalData, "Uint32Array", constructJSUint32Array, 1);
206 addConstructableFunction(globalData, "Int8Array", constructJSInt8Array, 1);
207 addConstructableFunction(globalData, "Int16Array", constructJSInt16Array, 1);
208 addConstructableFunction(globalData, "Int32Array", constructJSInt32Array, 1);
209 addConstructableFunction(globalData, "Float32Array", constructJSFloat32Array, 1);
210 addConstructableFunction(globalData, "Float64Array", constructJSFloat64Array, 1);
211
212 JSArray* array = constructEmptyArray(globalExec());
213 for (size_t i = 0; i < arguments.size(); ++i)
214 array->putDirectIndex(globalExec(), i, jsString(globalExec(), arguments[i]), false);
215 putDirect(globalData, Identifier(globalExec(), "arguments"), array);
216 }
217
218 void addFunction(JSGlobalData& globalData, const char* name, NativeFunction function, unsigned arguments)
219 {
220 Identifier identifier(globalExec(), name);
221 putDirect(globalData, identifier, JSFunction::create(globalExec(), this, arguments, identifier.ustring(), function));
222 }
223
224 void addConstructableFunction(JSGlobalData& globalData, const char* name, NativeFunction function, unsigned arguments)
225 {
226 Identifier identifier(globalExec(), name);
227 putDirect(globalData, identifier, JSFunction::create(globalExec(), this, arguments, identifier.ustring(), function, NoIntrinsic, function));
228 }
229};
230COMPILE_ASSERT(!IsInteger<GlobalObject>::value, WTF_IsInteger_GlobalObject_false);
231ASSERT_CLASS_FITS_IN_CELL(GlobalObject);
232
233const ClassInfo GlobalObject::s_info = { "global", &JSGlobalObject::s_info, 0, ExecState::globalObjectTable, CREATE_METHOD_TABLE(GlobalObject) };
234
235GlobalObject::GlobalObject(JSGlobalData& globalData, Structure* structure)
236 : JSGlobalObject(globalData, structure)
237{
238}
239
240static inline SourceCode jscSource(const char* utf8, const UString& filename)
241{
242 // Find the the first non-ascii character, or nul.
243 const char* pos = utf8;
244 while (*pos > 0)
245 pos++;
246 size_t asciiLength = pos - utf8;
247
248 // Fast case - string is all ascii.
249 if (!*pos)
250 return makeSource(UString(utf8, asciiLength), filename);
251
252 // Slow case - contains non-ascii characters, use fromUTF8WithLatin1Fallback.
253 ASSERT(*pos < 0);
254 ASSERT(strlen(utf8) == asciiLength + strlen(pos));
255 String source = String::fromUTF8WithLatin1Fallback(utf8, asciiLength + strlen(pos));
256 return makeSource(source.impl(), filename);
257}
258
259EncodedJSValue JSC_HOST_CALL functionPrint(ExecState* exec)
260{
261 for (unsigned i = 0; i < exec->argumentCount(); ++i) {
262 if (i)
263 putchar(' ');
264
265 printf("%s", exec->argument(i).toString(exec)->value(exec).utf8().data());
266 }
267
268 putchar('\n');
269 fflush(stdout);
270 return JSValue::encode(jsUndefined());
271}
272
273EncodedJSValue JSC_HOST_CALL functionDebug(ExecState* exec)
274{
275 fprintf(stderr, "--> %s\n", exec->argument(0).toString(exec)->value(exec).utf8().data());
276 return JSValue::encode(jsUndefined());
277}
278
279EncodedJSValue JSC_HOST_CALL functionJSCStack(ExecState* exec)
280{
281 String trace = "--> Stack trace:\n";
282 Vector<StackFrame> stackTrace;
283 Interpreter::getStackTrace(&exec->globalData(), stackTrace);
284 int i = 0;
285
286 for (Vector<StackFrame>::iterator iter = stackTrace.begin(); iter < stackTrace.end(); iter++) {
287 StackFrame level = *iter;
288 trace += String::format(" %i %s\n", i, level.toString(exec).utf8().data());
289 i++;
290 }
291 fprintf(stderr, "%s", trace.utf8().data());
292 return JSValue::encode(jsUndefined());
293}
294
295EncodedJSValue JSC_HOST_CALL functionGC(ExecState* exec)
296{
297 JSLock lock(SilenceAssertionsOnly);
298 exec->heap()->collectAllGarbage();
299 return JSValue::encode(jsUndefined());
300}
301
302#ifndef NDEBUG
303EncodedJSValue JSC_HOST_CALL functionReleaseExecutableMemory(ExecState* exec)
304{
305 JSLock lock(SilenceAssertionsOnly);
306 exec->globalData().releaseExecutableMemory();
307 return JSValue::encode(jsUndefined());
308}
309#endif
310
311EncodedJSValue JSC_HOST_CALL functionVersion(ExecState*)
312{
313 // We need this function for compatibility with the Mozilla JS tests but for now
314 // we don't actually do any version-specific handling
315 return JSValue::encode(jsUndefined());
316}
317
318EncodedJSValue JSC_HOST_CALL functionRun(ExecState* exec)
319{
320 UString fileName = exec->argument(0).toString(exec)->value(exec);
321 Vector<char> script;
322 if (!fillBufferWithContentsOfFile(fileName, script))
323 return JSValue::encode(throwError(exec, createError(exec, "Could not open file.")));
324
325 GlobalObject* globalObject = GlobalObject::create(exec->globalData(), GlobalObject::createStructure(exec->globalData(), jsNull()), Vector<UString>());
326
327 JSValue exception;
328 StopWatch stopWatch;
329 stopWatch.start();
330 evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), jscSource(script.data(), fileName), JSValue(), &exception);
331 stopWatch.stop();
332
333 if (!!exception) {
334 throwError(globalObject->globalExec(), exception);
335 return JSValue::encode(jsUndefined());
336 }
337
338 return JSValue::encode(jsNumber(stopWatch.getElapsedMS()));
339}
340
341EncodedJSValue JSC_HOST_CALL functionLoad(ExecState* exec)
342{
343 UString fileName = exec->argument(0).toString(exec)->value(exec);
344 Vector<char> script;
345 if (!fillBufferWithContentsOfFile(fileName, script))
346 return JSValue::encode(throwError(exec, createError(exec, "Could not open file.")));
347
348 JSGlobalObject* globalObject = exec->lexicalGlobalObject();
349
350 JSValue evaluationException;
351 JSValue result = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), jscSource(script.data(), fileName), JSValue(), &evaluationException);
352 if (evaluationException)
353 throwError(exec, evaluationException);
354 return JSValue::encode(result);
355}
356
357EncodedJSValue JSC_HOST_CALL functionCheckSyntax(ExecState* exec)
358{
359 UString fileName = exec->argument(0).toString(exec)->value(exec);
360 Vector<char> script;
361 if (!fillBufferWithContentsOfFile(fileName, script))
362 return JSValue::encode(throwError(exec, createError(exec, "Could not open file.")));
363
364 JSGlobalObject* globalObject = exec->lexicalGlobalObject();
365
366 StopWatch stopWatch;
367 stopWatch.start();
368
369 JSValue syntaxException;
370 bool validSyntax = checkSyntax(globalObject->globalExec(), jscSource(script.data(), fileName), &syntaxException);
371 stopWatch.stop();
372
373 if (!validSyntax)
374 throwError(exec, syntaxException);
375 return JSValue::encode(jsNumber(stopWatch.getElapsedMS()));
376}
377
378#if ENABLE(SAMPLING_FLAGS)
379EncodedJSValue JSC_HOST_CALL functionSetSamplingFlags(ExecState* exec)
380{
381 for (unsigned i = 0; i < exec->argumentCount(); ++i) {
382 unsigned flag = static_cast<unsigned>(exec->argument(i).toNumber(exec));
383 if ((flag >= 1) && (flag <= 32))
384 SamplingFlags::setFlag(flag);
385 }
386 return JSValue::encode(jsNull());
387}
388
389EncodedJSValue JSC_HOST_CALL functionClearSamplingFlags(ExecState* exec)
390{
391 for (unsigned i = 0; i < exec->argumentCount(); ++i) {
392 unsigned flag = static_cast<unsigned>(exec->argument(i).toNumber(exec));
393 if ((flag >= 1) && (flag <= 32))
394 SamplingFlags::clearFlag(flag);
395 }
396 return JSValue::encode(jsNull());
397}
398#endif
399
400EncodedJSValue JSC_HOST_CALL functionReadline(ExecState* exec)
401{
402 Vector<char, 256> line;
403 int c;
404 while ((c = getchar()) != EOF) {
405 // FIXME: Should we also break on \r?
406 if (c == '\n')
407 break;
408 line.append(c);
409 }
410 line.append('\0');
411 return JSValue::encode(jsString(exec, line.data()));
412}
413
414EncodedJSValue JSC_HOST_CALL functionPreciseTime(ExecState*)
415{
416 return JSValue::encode(jsNumber(currentTime()));
417}
418
419EncodedJSValue JSC_HOST_CALL functionQuit(ExecState*)
420{
421 exit(EXIT_SUCCESS);
422
423#if COMPILER(MSVC) && OS(WINCE)
424 // Without this, Visual Studio will complain that this method does not return a value.
425 return JSValue::encode(jsUndefined());
426#endif
427}
428
429// Use SEH for Release builds only to get rid of the crash report dialog
430// (luckily the same tests fail in Release and Debug builds so far). Need to
431// be in a separate main function because the jscmain function requires object
432// unwinding.
433
434#if COMPILER(MSVC) && !COMPILER(INTEL) && !defined(_DEBUG) && !OS(WINCE)
435#define TRY __try {
436#define EXCEPT(x) } __except (EXCEPTION_EXECUTE_HANDLER) { x; }
437#else
438#define TRY
439#define EXCEPT(x)
440#endif
441
442int jscmain(int argc, char** argv);
443
444int main(int argc, char** argv)
445{
446#if PLATFORM(IOS)
447 // Enabled IEEE754 denormal support.
448 fenv_t env;
449 fegetenv( &env );
450 env.__fpscr &= ~0x01000000u;
451 fesetenv( &env );
452#endif
453
454#if OS(WINDOWS)
455#if !OS(WINCE)
456 // Cygwin calls ::SetErrorMode(SEM_FAILCRITICALERRORS), which we will inherit. This is bad for
457 // testing/debugging, as it causes the post-mortem debugger not to be invoked. We reset the
458 // error mode here to work around Cygwin's behavior. See <http://webkit.org/b/55222>.
459 ::SetErrorMode(0);
460#endif
461
462#if defined(_DEBUG)
463 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
464 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
465 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
466 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
467 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
468 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
469#endif
470
471 timeBeginPeriod(1);
472#endif
473
474#if PLATFORM(QT)
475 QCoreApplication app(argc, argv);
476#endif
477
478 // Initialize JSC before getting JSGlobalData.
479#if ENABLE(SAMPLING_REGIONS)
480 WTF::initializeMainThread();
481#endif
482 JSC::initializeThreading();
483
484 // We can't use destructors in the following code because it uses Windows
485 // Structured Exception Handling
486 int res = 0;
487 TRY
488 res = jscmain(argc, argv);
489 EXCEPT(res = 3)
490 return res;
491}
492
493static bool runWithScripts(GlobalObject* globalObject, const Vector<Script>& scripts, bool dump)
494{
495 const char* script;
496 UString fileName;
497 Vector<char> scriptBuffer;
498
499 if (dump)
500 BytecodeGenerator::setDumpsGeneratedCode(true);
501
502 JSGlobalData& globalData = globalObject->globalData();
503
504#if ENABLE(SAMPLING_FLAGS)
505 SamplingFlags::start();
506#endif
507
508 bool success = true;
509 for (size_t i = 0; i < scripts.size(); i++) {
510 if (scripts[i].isFile) {
511 fileName = scripts[i].argument;
512 if (!fillBufferWithContentsOfFile(fileName, scriptBuffer))
513 return false; // fail early so we can catch missing files
514 script = scriptBuffer.data();
515 } else {
516 script = scripts[i].argument;
517 fileName = "[Command Line]";
518 }
519
520 globalData.startSampling();
521
522 JSValue evaluationException;
523 JSValue returnValue = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), jscSource(script, fileName), JSValue(), &evaluationException);
524 success = success && !evaluationException;
525 if (dump && !evaluationException)
526 printf("End: %s\n", returnValue.toString(globalObject->globalExec())->value(globalObject->globalExec()).utf8().data());
527 if (evaluationException) {
528 printf("Exception: %s\n", evaluationException.toString(globalObject->globalExec())->value(globalObject->globalExec()).utf8().data());
529 Identifier stackID(globalObject->globalExec(), "stack");
530 JSValue stackValue = evaluationException.get(globalObject->globalExec(), stackID);
531 if (!stackValue.isUndefinedOrNull())
532 printf("%s\n", stackValue.toString(globalObject->globalExec())->value(globalObject->globalExec()).utf8().data());
533 }
534
535 globalData.stopSampling();
536 globalObject->globalExec()->clearException();
537 }
538
539#if ENABLE(SAMPLING_FLAGS)
540 SamplingFlags::stop();
541#endif
542#if ENABLE(SAMPLING_REGIONS)
543 SamplingRegion::dump();
544#endif
545 globalData.dumpSampleData(globalObject->globalExec());
546#if ENABLE(SAMPLING_COUNTERS)
547 AbstractSamplingCounter::dump();
548#endif
549#if ENABLE(REGEXP_TRACING)
550 globalData.dumpRegExpTrace();
551#endif
552 return success;
553}
554
555#define RUNNING_FROM_XCODE 0
556
557static void runInteractive(GlobalObject* globalObject)
558{
559 UString interpreterName("Interpreter");
560
561 while (true) {
562#if HAVE(READLINE) && !RUNNING_FROM_XCODE
563 char* line = readline(interactivePrompt);
564 if (!line)
565 break;
566 if (line[0])
567 add_history(line);
568 JSValue evaluationException;
569 JSValue returnValue = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), jscSource(line, interpreterName), JSValue(), &evaluationException);
570 free(line);
571#else
572 printf("%s", interactivePrompt);
573 Vector<char, 256> line;
574 int c;
575 while ((c = getchar()) != EOF) {
576 // FIXME: Should we also break on \r?
577 if (c == '\n')
578 break;
579 line.append(c);
580 }
581 if (line.isEmpty())
582 break;
583 line.append('\0');
584
585 JSValue evaluationException;
586 JSValue returnValue = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), jscSource(line.data(), interpreterName), JSValue(), &evaluationException);
587#endif
588 if (evaluationException)
589 printf("Exception: %s\n", evaluationException.toString(globalObject->globalExec())->value(globalObject->globalExec()).utf8().data());
590 else
591 printf("%s\n", returnValue.toString(globalObject->globalExec())->value(globalObject->globalExec()).utf8().data());
592
593 globalObject->globalExec()->clearException();
594 }
595 printf("\n");
596}
597
598static NO_RETURN void printUsageStatement(bool help = false)
599{
600 fprintf(stderr, "Usage: jsc [options] [files] [-- arguments]\n");
601 fprintf(stderr, " -d Dumps bytecode (debug builds only)\n");
602 fprintf(stderr, " -e Evaluate argument as script code\n");
603 fprintf(stderr, " -f Specifies a source file (deprecated)\n");
604 fprintf(stderr, " -h|--help Prints this help message\n");
605 fprintf(stderr, " -i Enables interactive mode (default if no files are specified)\n");
606#if HAVE(SIGNAL_H)
607 fprintf(stderr, " -s Installs signal handlers that exit on a crash (Unix platforms only)\n");
608#endif
609
610 exit(help ? EXIT_SUCCESS : EXIT_FAILURE);
611}
612
613static void parseArguments(int argc, char** argv, CommandLine& options)
614{
615 int i = 1;
616 for (; i < argc; ++i) {
617 const char* arg = argv[i];
618 if (!strcmp(arg, "-f")) {
619 if (++i == argc)
620 printUsageStatement();
621 options.scripts.append(Script(true, argv[i]));
622 continue;
623 }
624 if (!strcmp(arg, "-e")) {
625 if (++i == argc)
626 printUsageStatement();
627 options.scripts.append(Script(false, argv[i]));
628 continue;
629 }
630 if (!strcmp(arg, "-i")) {
631 options.interactive = true;
632 continue;
633 }
634 if (!strcmp(arg, "-d")) {
635 options.dump = true;
636 continue;
637 }
638 if (!strcmp(arg, "-s")) {
639#if HAVE(SIGNAL_H)
640 signal(SIGILL, _exit);
641 signal(SIGFPE, _exit);
642 signal(SIGBUS, _exit);
643 signal(SIGSEGV, _exit);
644#endif
645 continue;
646 }
647 if (!strcmp(arg, "--")) {
648 ++i;
649 break;
650 }
651 if (!strcmp(arg, "-h") || !strcmp(arg, "--help"))
652 printUsageStatement(true);
653 options.scripts.append(Script(true, argv[i]));
654 }
655
656 if (options.scripts.isEmpty())
657 options.interactive = true;
658
659 for (; i < argc; ++i)
660 options.arguments.append(argv[i]);
661}
662
663int jscmain(int argc, char** argv)
664{
665 JSLock lock(SilenceAssertionsOnly);
666
667 RefPtr<JSGlobalData> globalData = JSGlobalData::create(ThreadStackTypeLarge, LargeHeap);
668
669 CommandLine options;
670 parseArguments(argc, argv, options);
671
672 GlobalObject* globalObject = GlobalObject::create(*globalData, GlobalObject::createStructure(*globalData, jsNull()), options.arguments);
673 bool success = runWithScripts(globalObject, options.scripts, options.dump);
674 if (options.interactive && success)
675 runInteractive(globalObject);
676
677 return success ? 0 : 3;
678}
679
680static bool fillBufferWithContentsOfFile(const UString& fileName, Vector<char>& buffer)
681{
682 FILE* f = fopen(fileName.utf8().data(), "r");
683 if (!f) {
684 fprintf(stderr, "Could not open file: %s\n", fileName.utf8().data());
685 return false;
686 }
687
688 size_t bufferSize = 0;
689 size_t bufferCapacity = 1024;
690
691 buffer.resize(bufferCapacity);
692
693 while (!feof(f) && !ferror(f)) {
694 bufferSize += fread(buffer.data() + bufferSize, 1, bufferCapacity - bufferSize, f);
695 if (bufferSize == bufferCapacity) { // guarantees space for trailing '\0'
696 bufferCapacity *= 2;
697 buffer.resize(bufferCapacity);
698 }
699 }
700 fclose(f);
701 buffer[bufferSize] = '\0';
702
703 if (buffer[0] == '#' && buffer[1] == '!')
704 buffer[0] = buffer[1] = '/';
705
706 return true;
707}
Note: See TracBrowser for help on using the repository browser.