source: webkit/trunk/JavaScriptCore/runtime/JSByteArray.h@ 39851

Last change on this file since 39851 was 39851, checked in by [email protected], 16 years ago

JavaScriptCore:

2009-01-12 Gavin Barraclough <[email protected]>

Reviewed by Oliver Hunt.

Make the JSImmediate interface private.

All manipulation of JS values should be through the JSValuePtr class, not by using JSImmediate
directly. The key missing methods on JSValuePtr are:

  • isCell() - check for values that are JSCell*s, and as such where asCell() may be used.
  • isInt32Fast() getInt32Fast() - fast check/access for integer immediates.
  • isUInt32Fast() getUInt32Fast() - ditto for unsigned integer immediates.

The JIT is allowed full access to JSImmediate, since it needs to be able to directly
manipulate JSValuePtrs. The Interpreter is provided access to perform operations directly
on JSValuePtrs through the new JSFastMath interface.

No performance impact.

  • API/JSCallbackObjectFunctions.h: (JSC::::toNumber):
  • API/JSValueRef.cpp: (JSValueIsEqual): (JSValueIsStrictEqual):
  • JavaScriptCore.exp:
  • bytecode/CodeBlock.h: (JSC::CodeBlock::isKnownNotImmediate):
  • bytecompiler/BytecodeGenerator.cpp: (JSC::keyForImmediateSwitch):
  • bytecompiler/BytecodeGenerator.h: (JSC::BytecodeGenerator::JSValueHashTraits::constructDeletedValue): (JSC::BytecodeGenerator::JSValueHashTraits::isDeletedValue):
  • interpreter/Interpreter.cpp: (JSC::jsLess): (JSC::jsLessEq): (JSC::jsAdd): (JSC::jsIsObjectType): (JSC::cachePrototypeChain): (JSC::Interpreter::tryCachePutByID): (JSC::Interpreter::tryCacheGetByID): (JSC::Interpreter::privateExecute): (JSC::Interpreter::tryCTICachePutByID): (JSC::Interpreter::tryCTICacheGetByID): (JSC::Interpreter::cti_op_add): (JSC::Interpreter::cti_op_get_by_id_self_fail): (JSC::Interpreter::cti_op_get_by_id_proto_list): (JSC::Interpreter::cti_op_instanceof): (JSC::Interpreter::cti_op_mul): (JSC::Interpreter::cti_op_get_by_val): (JSC::Interpreter::cti_op_get_by_val_byte_array): (JSC::Interpreter::cti_op_sub): (JSC::Interpreter::cti_op_put_by_val): (JSC::Interpreter::cti_op_put_by_val_array): (JSC::Interpreter::cti_op_put_by_val_byte_array): (JSC::Interpreter::cti_op_negate): (JSC::Interpreter::cti_op_div): (JSC::Interpreter::cti_op_eq): (JSC::Interpreter::cti_op_lshift): (JSC::Interpreter::cti_op_bitand): (JSC::Interpreter::cti_op_rshift): (JSC::Interpreter::cti_op_bitnot): (JSC::Interpreter::cti_op_neq): (JSC::Interpreter::cti_op_urshift): (JSC::Interpreter::cti_op_call_eval): (JSC::Interpreter::cti_op_throw): (JSC::Interpreter::cti_op_is_undefined): (JSC::Interpreter::cti_op_stricteq): (JSC::Interpreter::cti_op_nstricteq): (JSC::Interpreter::cti_op_switch_imm): (JSC::Interpreter::cti_vm_throw):
  • interpreter/Interpreter.h: (JSC::Interpreter::isJSArray): (JSC::Interpreter::isJSString): (JSC::Interpreter::isJSByteArray):
  • jit/JIT.cpp: (JSC::JIT::compileOpStrictEq): (JSC::JIT::privateCompileMainPass):
  • jit/JIT.h: (JSC::JIT::isStrictEqCaseHandledInJITCode):
  • jit/JITArithmetic.cpp: (JSC::JIT::compileFastArith_op_rshift): (JSC::JIT::compileFastArith_op_bitand): (JSC::JIT::compileFastArith_op_mod):
  • jit/JITCall.cpp: (JSC::JIT::unlinkCall): (JSC::JIT::compileOpCall):
  • jit/JITInlineMethods.h: (JSC::JIT::getConstantOperandImmediateInt): (JSC::JIT::isOperandConstantImmediateInt):
  • parser/Nodes.cpp: (JSC::processClauseList):
  • runtime/ArrayPrototype.cpp: (JSC::arrayProtoFuncIndexOf): (JSC::arrayProtoFuncLastIndexOf):
  • runtime/BooleanPrototype.cpp: (JSC::booleanProtoFuncValueOf):
  • runtime/Collector.cpp: (JSC::Heap::protect): (JSC::Heap::unprotect): (JSC::Heap::heap):
  • runtime/JSByteArray.cpp: (JSC::JSByteArray::getOwnPropertySlot):
  • runtime/JSByteArray.h: (JSC::JSByteArray::getIndex):
  • runtime/JSCell.cpp:
  • runtime/JSCell.h: (JSC::JSValuePtr::isNumberCell): (JSC::JSValuePtr::asCell): (JSC::JSValuePtr::isNumber):
  • runtime/JSGlobalObjectFunctions.cpp: (JSC::globalFuncParseInt):
  • runtime/JSImmediate.h: (JSC::js0): (JSC::jsImpossibleValue): (JSC::JSValuePtr::toInt32): (JSC::JSValuePtr::toUInt32): (JSC::JSValuePtr::isCell): (JSC::JSValuePtr::isInt32Fast): (JSC::JSValuePtr::getInt32Fast): (JSC::JSValuePtr::isUInt32Fast): (JSC::JSValuePtr::getUInt32Fast): (JSC::JSValuePtr::makeInt32Fast): (JSC::JSValuePtr::areBothInt32Fast): (JSC::JSFastMath::canDoFastBitwiseOperations): (JSC::JSFastMath::equal): (JSC::JSFastMath::notEqual): (JSC::JSFastMath::andImmediateNumbers): (JSC::JSFastMath::xorImmediateNumbers): (JSC::JSFastMath::orImmediateNumbers): (JSC::JSFastMath::canDoFastRshift): (JSC::JSFastMath::canDoFastUrshift): (JSC::JSFastMath::rightShiftImmediateNumbers): (JSC::JSFastMath::canDoFastAdditiveOperations): (JSC::JSFastMath::addImmediateNumbers): (JSC::JSFastMath::subImmediateNumbers): (JSC::JSFastMath::incImmediateNumber): (JSC::JSFastMath::decImmediateNumber):
  • runtime/JSNumberCell.h: (JSC::JSValuePtr::asNumberCell): (JSC::jsNumber): (JSC::JSValuePtr::uncheckedGetNumber): (JSC::JSNumberCell::toInt32): (JSC::JSNumberCell::toUInt32): (JSC::JSValuePtr::toJSNumber): (JSC::JSValuePtr::getNumber): (JSC::JSValuePtr::numberToInt32): (JSC::JSValuePtr::numberToUInt32):
  • runtime/JSObject.h: (JSC::JSValuePtr::isObject): (JSC::JSValuePtr::get): (JSC::JSValuePtr::put):
  • runtime/JSValue.cpp: (JSC::JSValuePtr::toInteger): (JSC::JSValuePtr::toIntegerPreserveNaN):
  • runtime/JSValue.h:
  • runtime/Operations.cpp: (JSC::JSValuePtr::equalSlowCase): (JSC::JSValuePtr::strictEqualSlowCase):
  • runtime/Operations.h: (JSC::JSValuePtr::equal): (JSC::JSValuePtr::equalSlowCaseInline): (JSC::JSValuePtr::strictEqual): (JSC::JSValuePtr::strictEqualSlowCaseInline):
  • runtime/Protect.h: (JSC::gcProtect): (JSC::gcUnprotect):
  • runtime/StringPrototype.cpp: (JSC::stringProtoFuncCharAt): (JSC::stringProtoFuncCharCodeAt):
  • runtime/Structure.cpp: (JSC::Structure::createCachedPrototypeChain):

WebCore:

2009-01-12 Gavin Barraclough <[email protected]>

Reviewed by Oliver Hunt.

Deprecate JSValuePtr::getNumber() - two ways to get a number should be enough.

  • bindings/js/JSSQLTransactionCustom.cpp: (WebCore::JSSQLTransaction::executeSql):
  • bindings/objc/WebScriptObject.mm: (+[WebScriptObject _convertValueToObjcValue:originRootObject:rootObject:]):

WebKit/mac:

2009-01-12 Gavin Barraclough <[email protected]>

Reviewed by Oliver Hunt.

Deprecate JSValuePtr::getNumber() - two ways to get a number should be enough.

  • WebView/WebView.mm: (aeDescFromJSValue):
File size: 4.0 KB
Line 
1/*
2 * Copyright (C) 2009 Apple Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef JSByteArray_h
27#define JSByteArray_h
28
29#include "ByteArray.h"
30#include "JSObject.h"
31
32namespace JSC {
33
34 class JSByteArray : public JSObject {
35 friend class Interpreter;
36 public:
37 bool canAccessIndex(unsigned i) { return i < m_storage->length(); }
38 JSValuePtr getIndex(ExecState* exec, unsigned i)
39 {
40 ASSERT(canAccessIndex(i));
41 return jsNumber(exec, m_storage->data()[i]);
42 }
43
44 void setIndex(unsigned i, int value)
45 {
46 ASSERT(canAccessIndex(i));
47 if (value & ~0xFF) {
48 if (value < 0)
49 value = 0;
50 else
51 value = 255;
52 }
53 m_storage->data()[i] = static_cast<unsigned char>(value);
54 }
55
56 void setIndex(unsigned i, double value)
57 {
58 ASSERT(canAccessIndex(i));
59 if (!(value > 0)) // Clamp NaN to 0
60 value = 0;
61 else if (value > 255)
62 value = 255;
63 m_storage->data()[i] = static_cast<unsigned char>(value + 0.5);
64 }
65
66 void setIndex(ExecState* exec, unsigned i, JSValuePtr value)
67 {
68 double byteValue = value->toNumber(exec);
69 if (exec->hadException())
70 return;
71 if (canAccessIndex(i))
72 setIndex(i, byteValue);
73 }
74
75 JSByteArray(ExecState* exec, PassRefPtr<Structure>, ByteArray* storage, const JSC::ClassInfo* = &s_defaultInfo);
76 static PassRefPtr<Structure> createStructure(JSValuePtr prototype);
77
78 virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::PropertySlot&);
79 virtual bool getOwnPropertySlot(JSC::ExecState*, unsigned propertyName, JSC::PropertySlot&);
80 virtual void put(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSValuePtr, JSC::PutPropertySlot&);
81 virtual void put(JSC::ExecState*, unsigned propertyName, JSC::JSValuePtr);
82
83 virtual void getPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&);
84
85 virtual const ClassInfo* classInfo() const { return m_classInfo; }
86 static const ClassInfo s_defaultInfo;
87
88 size_t length() const { return m_storage->length(); }
89
90 private:
91 enum VPtrStealingHackType { VPtrStealingHack };
92 JSByteArray(VPtrStealingHackType)
93 : JSObject(createStructure(jsNull()))
94 , m_classInfo(0)
95 {
96 }
97
98 RefPtr<ByteArray> m_storage;
99 const ClassInfo* m_classInfo;
100 };
101
102 JSByteArray* asByteArray(JSValuePtr value);
103 inline JSByteArray* asByteArray(JSValuePtr value)
104 {
105 return static_cast<JSByteArray*>(asCell(value));
106 }
107}
108
109#endif
Note: See TracBrowser for help on using the repository browser.