| // -*- mode: c++; c-basic-offset: 4 -*- |
| /* |
| * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
| * |
| * Redistribution and use in source and binary forms, with or without |
| * modification, are permitted provided that the following conditions |
| * are met: |
| * 1. Redistributions of source code must retain the above copyright |
| * notice, this list of conditions and the following disclaimer. |
| * 2. Redistributions in binary form must reproduce the above copyright |
| * notice, this list of conditions and the following disclaimer in the |
| * documentation and/or other materials provided with the distribution. |
| * |
| * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| |
| #include "JSClassRef.h" |
| #include "JSObjectRef.h" |
| #include "identifier.h" |
| |
| using namespace KJS; |
| |
| const JSClassDefinition kJSClassDefinitionNull = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
| |
| __JSClass::__JSClass(JSClassDefinition* definition) |
| : refCount(0) |
| , className(definition->className) |
| , parentClass(definition->parentClass) |
| , staticValues(0) |
| , staticFunctions(0) |
| , initialize(definition->initialize) |
| , finalize(definition->finalize) |
| , hasProperty(definition->hasProperty) |
| , getProperty(definition->getProperty) |
| , setProperty(definition->setProperty) |
| , deleteProperty(definition->deleteProperty) |
| , getPropertyNames(definition->getPropertyNames) |
| , callAsFunction(definition->callAsFunction) |
| , callAsConstructor(definition->callAsConstructor) |
| , hasInstance(definition->hasInstance) |
| , convertToType(definition->convertToType) |
| { |
| if (JSStaticValue* staticValue = definition->staticValues) { |
| staticValues = new StaticValuesTable(); |
| while (staticValue->name) { |
| staticValues->add(Identifier(staticValue->name).ustring().rep(), |
| new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes)); |
| ++staticValue; |
| } |
| } |
| |
| if (JSStaticFunction* staticFunction = definition->staticFunctions) { |
| staticFunctions = new StaticFunctionsTable(); |
| while (staticFunction->name) { |
| staticFunctions->add(Identifier(staticFunction->name).ustring().rep(), |
| new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes)); |
| ++staticFunction; |
| } |
| } |
| } |
| |
| __JSClass::~__JSClass() |
| { |
| if (staticValues) { |
| deleteAllValues(*staticValues); |
| delete staticValues; |
| } |
| |
| if (staticFunctions) { |
| deleteAllValues(*staticFunctions); |
| delete staticFunctions; |
| } |
| } |