gfx/skia/trunk/src/animator/SkScript.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2006 The Android Open Source Project
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #ifndef SkScript_DEFINED
michael@0 11 #define SkScript_DEFINED
michael@0 12
michael@0 13 #include "SkOperand.h"
michael@0 14 #include "SkIntArray.h"
michael@0 15 #include "SkTDict.h"
michael@0 16 #include "SkTDStack.h"
michael@0 17
michael@0 18 class SkAnimateMaker;
michael@0 19
michael@0 20 class SkScriptEngine {
michael@0 21 public:
michael@0 22 enum Error {
michael@0 23 kNoError,
michael@0 24 kArrayIndexOutOfBounds,
michael@0 25 kCouldNotFindReferencedID,
michael@0 26 kDotOperatorExpectsObject,
michael@0 27 kErrorInArrrayIndex,
michael@0 28 kErrorInFunctionParameters,
michael@0 29 kExpectedArray,
michael@0 30 kExpectedBooleanExpression,
michael@0 31 kExpectedFieldName,
michael@0 32 kExpectedHex,
michael@0 33 kExpectedIntForConditionOperator,
michael@0 34 kExpectedNumber,
michael@0 35 kExpectedNumberForArrayIndex,
michael@0 36 kExpectedOperator,
michael@0 37 kExpectedToken,
michael@0 38 kExpectedTokenBeforeDotOperator,
michael@0 39 kExpectedValue,
michael@0 40 kHandleMemberFailed,
michael@0 41 kHandleMemberFunctionFailed,
michael@0 42 kHandleUnboxFailed,
michael@0 43 kIndexOutOfRange,
michael@0 44 kMismatchedArrayBrace,
michael@0 45 kMismatchedBrackets,
michael@0 46 kNoFunctionHandlerFound,
michael@0 47 kPrematureEnd,
michael@0 48 kTooManyParameters,
michael@0 49 kTypeConversionFailed,
michael@0 50 kUnterminatedString
michael@0 51 };
michael@0 52
michael@0 53 enum SkOpType {
michael@0 54 kNoType,
michael@0 55 kInt = 1,
michael@0 56 kScalar = 2,
michael@0 57 kString = 4,
michael@0 58 kArray = 8,
michael@0 59 kObject = 16
michael@0 60 // kStruct = 32
michael@0 61 };
michael@0 62
michael@0 63 typedef bool (*_boxCallBack)(void* userStorage, SkScriptValue* result);
michael@0 64 typedef bool (*_functionCallBack)(const char* func, size_t len, SkTDArray<SkScriptValue>& params,
michael@0 65 void* userStorage, SkScriptValue* result);
michael@0 66 typedef bool (*_memberCallBack)(const char* member, size_t len, void* object,
michael@0 67 void* userStorage, SkScriptValue* result);
michael@0 68 typedef bool (*_memberFunctionCallBack)(const char* member, size_t len, void* object,
michael@0 69 SkTDArray<SkScriptValue>& params, void* userStorage, SkScriptValue* result);
michael@0 70 // typedef bool (*_objectToStringCallBack)(void* object, void* userStorage, SkScriptValue* result);
michael@0 71 typedef bool (*_propertyCallBack)(const char* prop, size_t len, void* userStorage, SkScriptValue* result);
michael@0 72 typedef bool (*_unboxCallBack)(void* userStorage, SkScriptValue* result);
michael@0 73 SkScriptEngine(SkOpType returnType);
michael@0 74 ~SkScriptEngine();
michael@0 75 void boxCallBack(_boxCallBack func, void* userStorage);
michael@0 76 bool convertTo(SkDisplayTypes , SkScriptValue* );
michael@0 77 bool evaluateScript(const char** script, SkScriptValue* value);
michael@0 78 void forget(SkTypedArray* array);
michael@0 79 void functionCallBack(_functionCallBack func, void* userStorage);
michael@0 80 Error getError() const { return fError; }
michael@0 81 #ifdef SK_DEBUG
michael@0 82 bool getErrorString(SkString* err) const;
michael@0 83 #endif
michael@0 84 void memberCallBack(_memberCallBack , void* userStorage);
michael@0 85 void memberFunctionCallBack(_memberFunctionCallBack , void* userStorage);
michael@0 86 // void objectToStringCallBack(_objectToStringCallBack , void* userStorage);
michael@0 87 void propertyCallBack(_propertyCallBack prop, void* userStorage);
michael@0 88 void track(SkTypedArray* array);
michael@0 89 void track(SkString* string);
michael@0 90 void unboxCallBack(_unboxCallBack func, void* userStorage);
michael@0 91 static bool ConvertTo(SkScriptEngine* , SkDisplayTypes toType, SkScriptValue* value);
michael@0 92 static SkScalar IntToScalar(int32_t );
michael@0 93 static SkDisplayTypes ToDisplayType(SkOpType type);
michael@0 94 static SkOpType ToOpType(SkDisplayTypes type);
michael@0 95 static bool ValueToString(SkScriptValue value, SkString* string);
michael@0 96
michael@0 97 enum CallBackType {
michael@0 98 kBox,
michael@0 99 kFunction,
michael@0 100 kMember,
michael@0 101 kMemberFunction,
michael@0 102 // kObjectToString,
michael@0 103 kProperty,
michael@0 104 kUnbox
michael@0 105 };
michael@0 106
michael@0 107 struct UserCallBack {
michael@0 108 CallBackType fCallBackType;
michael@0 109 void* fUserStorage;
michael@0 110 union {
michael@0 111 _boxCallBack fBoxCallBack;
michael@0 112 _functionCallBack fFunctionCallBack;
michael@0 113 _memberCallBack fMemberCallBack;
michael@0 114 _memberFunctionCallBack fMemberFunctionCallBack;
michael@0 115 // _objectToStringCallBack fObjectToStringCallBack;
michael@0 116 _propertyCallBack fPropertyCallBack;
michael@0 117 _unboxCallBack fUnboxCallBack;
michael@0 118 };
michael@0 119 };
michael@0 120
michael@0 121 enum SkOp {
michael@0 122 kUnassigned,
michael@0 123 kAdd,
michael@0 124 kAddInt = kAdd,
michael@0 125 kAddScalar,
michael@0 126 kAddString, // string concat
michael@0 127 kArrayOp,
michael@0 128 kBitAnd,
michael@0 129 kBitNot,
michael@0 130 kBitOr,
michael@0 131 kDivide,
michael@0 132 kDivideInt = kDivide,
michael@0 133 kDivideScalar,
michael@0 134 kElse,
michael@0 135 kEqual,
michael@0 136 kEqualInt = kEqual,
michael@0 137 kEqualScalar,
michael@0 138 kEqualString,
michael@0 139 kFlipOps,
michael@0 140 kGreaterEqual,
michael@0 141 kGreaterEqualInt = kGreaterEqual,
michael@0 142 kGreaterEqualScalar,
michael@0 143 kGreaterEqualString,
michael@0 144 kIf,
michael@0 145 kLogicalAnd,
michael@0 146 kLogicalNot,
michael@0 147 kLogicalOr,
michael@0 148 kMinus,
michael@0 149 kMinusInt = kMinus,
michael@0 150 kMinusScalar,
michael@0 151 kModulo,
michael@0 152 kModuloInt = kModulo,
michael@0 153 kModuloScalar,
michael@0 154 kMultiply,
michael@0 155 kMultiplyInt = kMultiply,
michael@0 156 kMultiplyScalar,
michael@0 157 kParen,
michael@0 158 kShiftLeft,
michael@0 159 kShiftRight, // signed
michael@0 160 kSubtract,
michael@0 161 kSubtractInt = kSubtract,
michael@0 162 kSubtractScalar,
michael@0 163 kXor,
michael@0 164 kArtificialOp = 0x40
michael@0 165 };
michael@0 166
michael@0 167 enum SkOpBias {
michael@0 168 kNoBias,
michael@0 169 kTowardsNumber = 0,
michael@0 170 kTowardsString
michael@0 171 };
michael@0 172
michael@0 173 protected:
michael@0 174
michael@0 175 struct SkOperatorAttributes {
michael@0 176 unsigned int fLeftType : 3; // SkOpType, but only lower values
michael@0 177 unsigned int fRightType : 3; // SkOpType, but only lower values
michael@0 178 SkOpBias fBias : 1;
michael@0 179 };
michael@0 180
michael@0 181 struct SkSuppress { // !!! could be compressed to a long
michael@0 182 SkOp fOperator; // operand which enabled suppression
michael@0 183 int fOpStackDepth; // depth when suppression operator was found
michael@0 184 SkBool8 fSuppress; // set if suppression happens now, as opposed to later
michael@0 185 SkBool8 fElse; // set on the : half of ? :
michael@0 186 };
michael@0 187
michael@0 188 static const SkOperatorAttributes gOpAttributes[];
michael@0 189 static const signed char gPrecedence[];
michael@0 190 int arithmeticOp(char ch, char nextChar, bool lastPush);
michael@0 191 void commonCallBack(CallBackType type, UserCallBack& callBack, void* userStorage);
michael@0 192 bool convertParams(SkTDArray<SkScriptValue>&, const SkFunctionParamType* ,
michael@0 193 int paramTypeCount);
michael@0 194 void convertToString(SkOperand& operand, SkDisplayTypes type) {
michael@0 195 SkScriptValue scriptValue;
michael@0 196 scriptValue.fOperand = operand;
michael@0 197 scriptValue.fType = type;
michael@0 198 convertTo(SkType_String, &scriptValue);
michael@0 199 operand = scriptValue.fOperand;
michael@0 200 }
michael@0 201 bool evaluateDot(const char*& script, bool suppressed);
michael@0 202 bool evaluateDotParam(const char*& script, bool suppressed, const char* field, size_t fieldLength);
michael@0 203 bool functionParams(const char** scriptPtr, SkTDArray<SkScriptValue>& params);
michael@0 204 bool handleArrayIndexer(const char** scriptPtr, bool suppressed);
michael@0 205 bool handleBox(SkScriptValue* value);
michael@0 206 bool handleFunction(const char** scriptPtr, bool suppressed);
michael@0 207 bool handleMember(const char* field, size_t len, void* object);
michael@0 208 bool handleMemberFunction(const char* field, size_t len, void* object, SkTDArray<SkScriptValue>& params);
michael@0 209 // bool handleObjectToString(void* object);
michael@0 210 bool handleProperty(bool suppressed);
michael@0 211 bool handleUnbox(SkScriptValue* scriptValue);
michael@0 212 bool innerScript(const char** scriptPtr, SkScriptValue* value);
michael@0 213 int logicalOp(char ch, char nextChar);
michael@0 214 Error opError();
michael@0 215 bool processOp();
michael@0 216 void setAnimateMaker(SkAnimateMaker* maker) { fMaker = maker; }
michael@0 217 bool setError(Error , const char* pos);
michael@0 218 enum SkBraceStyle {
michael@0 219 // kStructBrace,
michael@0 220 kArrayBrace,
michael@0 221 kFunctionBrace
michael@0 222 };
michael@0 223
michael@0 224 #if 0
michael@0 225 SkIntArray(SkBraceStyle) fBraceStack; // curly, square, function paren
michael@0 226 SkIntArray(SkOp) fOpStack;
michael@0 227 SkIntArray(SkOpType) fTypeStack;
michael@0 228 SkTDOperandArray fOperandStack;
michael@0 229 SkTDArray<SkSuppress> fSuppressStack;
michael@0 230 #else
michael@0 231 SkTDStack<SkBraceStyle> fBraceStack; // curly, square, function paren
michael@0 232 SkTDStack<SkOp> fOpStack;
michael@0 233 SkTDStack<SkOpType> fTypeStack;
michael@0 234 SkTDStack<SkOperand> fOperandStack;
michael@0 235 SkTDStack<SkSuppress> fSuppressStack;
michael@0 236 #endif
michael@0 237 SkAnimateMaker* fMaker;
michael@0 238 SkTDTypedArrayArray fTrackArray;
michael@0 239 SkTDStringArray fTrackString;
michael@0 240 const char* fToken; // one-deep stack
michael@0 241 size_t fTokenLength;
michael@0 242 SkTDArray<UserCallBack> fUserCallBacks;
michael@0 243 SkOpType fReturnType;
michael@0 244 Error fError;
michael@0 245 int fErrorPosition;
michael@0 246 private:
michael@0 247 friend class SkTypedArray;
michael@0 248 #ifdef SK_SUPPORT_UNITTEST
michael@0 249 public:
michael@0 250 static void UnitTest();
michael@0 251 #endif
michael@0 252 };
michael@0 253
michael@0 254 #ifdef SK_SUPPORT_UNITTEST
michael@0 255
michael@0 256 struct SkScriptNAnswer {
michael@0 257 const char* fScript;
michael@0 258 SkDisplayTypes fType;
michael@0 259 int32_t fIntAnswer;
michael@0 260 SkScalar fScalarAnswer;
michael@0 261 const char* fStringAnswer;
michael@0 262 };
michael@0 263
michael@0 264 #endif
michael@0 265
michael@0 266 #endif // SkScript_DEFINED

mercurial