BooleanConstructor.cpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 "BooleanConstructor.h"
  22. #include "BooleanPrototype.h"
  23. #include "JSGlobalObject.h"
  24. #include "Operations.h"
  25. namespace JSC {
  26. ASSERT_HAS_TRIVIAL_DESTRUCTOR(BooleanConstructor);
  27. const ClassInfo BooleanConstructor::s_info = { "Function", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(BooleanConstructor) };
  28. BooleanConstructor::BooleanConstructor(JSGlobalObject* globalObject, Structure* structure)
  29. : InternalFunction(globalObject, structure)
  30. {
  31. }
  32. void BooleanConstructor::finishCreation(ExecState* exec, BooleanPrototype* booleanPrototype)
  33. {
  34. Base::finishCreation(exec->vm(), booleanPrototype->classInfo()->className);
  35. putDirectWithoutTransition(exec->vm(), exec->propertyNames().prototype, booleanPrototype, DontEnum | DontDelete | ReadOnly);
  36. // no. of arguments for constructor
  37. putDirectWithoutTransition(exec->vm(), exec->propertyNames().length, jsNumber(1), ReadOnly | DontDelete | DontEnum);
  38. }
  39. // ECMA 15.6.2
  40. JSObject* constructBoolean(ExecState* exec, const ArgList& args)
  41. {
  42. BooleanObject* obj = BooleanObject::create(exec->vm(), asInternalFunction(exec->callee())->globalObject()->booleanObjectStructure());
  43. obj->setInternalValue(exec->vm(), jsBoolean(args.at(0).toBoolean(exec)));
  44. return obj;
  45. }
  46. static EncodedJSValue JSC_HOST_CALL constructWithBooleanConstructor(ExecState* exec)
  47. {
  48. ArgList args(exec);
  49. return JSValue::encode(constructBoolean(exec, args));
  50. }
  51. ConstructType BooleanConstructor::getConstructData(JSCell*, ConstructData& constructData)
  52. {
  53. constructData.native.function = constructWithBooleanConstructor;
  54. return ConstructTypeHost;
  55. }
  56. // ECMA 15.6.1
  57. static EncodedJSValue JSC_HOST_CALL callBooleanConstructor(ExecState* exec)
  58. {
  59. return JSValue::encode(jsBoolean(exec->argument(0).toBoolean(exec)));
  60. }
  61. CallType BooleanConstructor::getCallData(JSCell*, CallData& callData)
  62. {
  63. callData.native.function = callBooleanConstructor;
  64. return CallTypeHost;
  65. }
  66. JSObject* constructBooleanFromImmediateBoolean(ExecState* exec, JSGlobalObject* globalObject, JSValue immediateBooleanValue)
  67. {
  68. BooleanObject* obj = BooleanObject::create(exec->vm(), globalObject->booleanObjectStructure());
  69. obj->setInternalValue(exec->vm(), immediateBooleanValue);
  70. return obj;
  71. }
  72. } // namespace JSC