NativeErrorConstructor.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
  3. * Copyright (C) 2003, 2008 Apple Inc. All rights reserved.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. *
  19. */
  20. #include "config.h"
  21. #include "NativeErrorConstructor.h"
  22. #include "ErrorInstance.h"
  23. #include "JSFunction.h"
  24. #include "JSString.h"
  25. #include "NativeErrorPrototype.h"
  26. #include "Operations.h"
  27. namespace JSC {
  28. ASSERT_HAS_TRIVIAL_DESTRUCTOR(NativeErrorConstructor);
  29. const ClassInfo NativeErrorConstructor::s_info = { "Function", &InternalFunction::s_info, 0, 0, CREATE_METHOD_TABLE(NativeErrorConstructor) };
  30. NativeErrorConstructor::NativeErrorConstructor(JSGlobalObject* globalObject, Structure* structure)
  31. : InternalFunction(globalObject, structure)
  32. {
  33. }
  34. void NativeErrorConstructor::visitChildren(JSCell* cell, SlotVisitor& visitor)
  35. {
  36. NativeErrorConstructor* thisObject = jsCast<NativeErrorConstructor*>(cell);
  37. ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
  38. COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
  39. ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
  40. InternalFunction::visitChildren(thisObject, visitor);
  41. visitor.append(&thisObject->m_errorStructure);
  42. }
  43. static EncodedJSValue JSC_HOST_CALL constructWithNativeErrorConstructor(ExecState* exec)
  44. {
  45. JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined();
  46. Structure* errorStructure = static_cast<NativeErrorConstructor*>(exec->callee())->errorStructure();
  47. ASSERT(errorStructure);
  48. return JSValue::encode(ErrorInstance::create(exec, errorStructure, message));
  49. }
  50. ConstructType NativeErrorConstructor::getConstructData(JSCell*, ConstructData& constructData)
  51. {
  52. constructData.native.function = constructWithNativeErrorConstructor;
  53. return ConstructTypeHost;
  54. }
  55. static EncodedJSValue JSC_HOST_CALL callNativeErrorConstructor(ExecState* exec)
  56. {
  57. JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined();
  58. Structure* errorStructure = static_cast<NativeErrorConstructor*>(exec->callee())->errorStructure();
  59. return JSValue::encode(ErrorInstance::create(exec, errorStructure, message));
  60. }
  61. CallType NativeErrorConstructor::getCallData(JSCell*, CallData& callData)
  62. {
  63. callData.native.function = callNativeErrorConstructor;
  64. return CallTypeHost;
  65. }
  66. } // namespace JSC