ErrorConstructor.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 "ErrorConstructor.h"
  22. #include "ErrorPrototype.h"
  23. #include "JSGlobalObject.h"
  24. #include "JSString.h"
  25. #include "Operations.h"
  26. namespace JSC {
  27. ASSERT_HAS_TRIVIAL_DESTRUCTOR(ErrorConstructor);
  28. const ClassInfo ErrorConstructor::s_info = { "Function", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(ErrorConstructor) };
  29. ErrorConstructor::ErrorConstructor(JSGlobalObject* globalObject, Structure* structure)
  30. : InternalFunction(globalObject, structure)
  31. {
  32. }
  33. void ErrorConstructor::finishCreation(ExecState* exec, ErrorPrototype* errorPrototype)
  34. {
  35. Base::finishCreation(exec->vm(), errorPrototype->classInfo()->className);
  36. // ECMA 15.11.3.1 Error.prototype
  37. putDirectWithoutTransition(exec->vm(), exec->propertyNames().prototype, errorPrototype, DontEnum | DontDelete | ReadOnly);
  38. putDirectWithoutTransition(exec->vm(), exec->propertyNames().length, jsNumber(1), DontDelete | ReadOnly | DontEnum);
  39. }
  40. // ECMA 15.9.3
  41. static EncodedJSValue JSC_HOST_CALL constructWithErrorConstructor(ExecState* exec)
  42. {
  43. JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined();
  44. Structure* errorStructure = asInternalFunction(exec->callee())->globalObject()->errorStructure();
  45. return JSValue::encode(ErrorInstance::create(exec, errorStructure, message));
  46. }
  47. ConstructType ErrorConstructor::getConstructData(JSCell*, ConstructData& constructData)
  48. {
  49. constructData.native.function = constructWithErrorConstructor;
  50. return ConstructTypeHost;
  51. }
  52. static EncodedJSValue JSC_HOST_CALL callErrorConstructor(ExecState* exec)
  53. {
  54. JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined();
  55. Structure* errorStructure = asInternalFunction(exec->callee())->globalObject()->errorStructure();
  56. return JSValue::encode(ErrorInstance::create(exec, errorStructure, message));
  57. }
  58. CallType ErrorConstructor::getCallData(JSCell*, CallData& callData)
  59. {
  60. callData.native.function = callErrorConstructor;
  61. return CallTypeHost;
  62. }
  63. } // namespace JSC