Operations.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
  3. * Copyright (C) 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 Library 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. * Library General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Library General Public License
  16. * along with this library; see the file COPYING.LIB. If not, write to
  17. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18. * Boston, MA 02110-1301, USA.
  19. *
  20. */
  21. #include "config.h"
  22. #include "Operations.h"
  23. #include "Error.h"
  24. #include "JSObject.h"
  25. #include "JSString.h"
  26. #include <math.h>
  27. #include <stdio.h>
  28. #include <wtf/MathExtras.h>
  29. namespace JSC {
  30. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  31. bool JSValue::equalSlowCase(ExecState* exec, JSValue v1, JSValue v2)
  32. {
  33. return equalSlowCaseInline(exec, v1, v2);
  34. }
  35. bool JSValue::strictEqualSlowCase(ExecState* exec, JSValue v1, JSValue v2)
  36. {
  37. return strictEqualSlowCaseInline(exec, v1, v2);
  38. }
  39. NEVER_INLINE JSValue jsAddSlowCase(CallFrame* callFrame, JSValue v1, JSValue v2)
  40. {
  41. // exception for the Date exception in defaultValue()
  42. JSValue p1 = v1.toPrimitive(callFrame);
  43. JSValue p2 = v2.toPrimitive(callFrame);
  44. if (p1.isString())
  45. return jsString(callFrame, asString(p1), p2.toString(callFrame));
  46. if (p2.isString())
  47. return jsString(callFrame, p1.toString(callFrame), asString(p2));
  48. return jsNumber(p1.toNumber(callFrame) + p2.toNumber(callFrame));
  49. }
  50. #endif // #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  51. JSValue jsTypeStringForValue(VM& vm, JSGlobalObject* globalObject, JSValue v)
  52. {
  53. if (v.isUndefined())
  54. return vm.smallStrings.undefinedString();
  55. if (v.isBoolean())
  56. return vm.smallStrings.booleanString();
  57. if (v.isNumber())
  58. return vm.smallStrings.numberString();
  59. if (v.isString())
  60. return vm.smallStrings.stringString();
  61. if (v.isObject()) {
  62. // Return "undefined" for objects that should be treated
  63. // as null when doing comparisons.
  64. if (asObject(v)->structure()->masqueradesAsUndefined(globalObject))
  65. return vm.smallStrings.undefinedString();
  66. CallData callData;
  67. JSObject* object = asObject(v);
  68. if (object->methodTable()->getCallData(object, callData) != CallTypeNone)
  69. return vm.smallStrings.functionString();
  70. }
  71. return vm.smallStrings.objectString();
  72. }
  73. JSValue jsTypeStringForValue(CallFrame* callFrame, JSValue v)
  74. {
  75. return jsTypeStringForValue(callFrame->vm(), callFrame->lexicalGlobalObject(), v);
  76. }
  77. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  78. bool jsIsObjectType(CallFrame* callFrame, JSValue v)
  79. {
  80. if (!v.isCell())
  81. return v.isNull();
  82. JSType type = v.asCell()->structure()->typeInfo().type();
  83. if (type == StringType)
  84. return false;
  85. if (type >= ObjectType) {
  86. if (asObject(v)->structure()->masqueradesAsUndefined(callFrame->lexicalGlobalObject()))
  87. return false;
  88. CallData callData;
  89. JSObject* object = asObject(v);
  90. if (object->methodTable()->getCallData(object, callData) != CallTypeNone)
  91. return false;
  92. }
  93. return true;
  94. }
  95. bool jsIsFunctionType(JSValue v)
  96. {
  97. if (v.isObject()) {
  98. CallData callData;
  99. JSObject* object = asObject(v);
  100. if (object->methodTable()->getCallData(object, callData) != CallTypeNone)
  101. return true;
  102. }
  103. return false;
  104. }
  105. #endif // #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  106. } // namespace JSC