Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use error messages and IDs from Tamarin

resources/ErrorConstants.xml is taken from Tamarin sources. Tamarin is
licensed under MPL 2.0, which is compatible with LGPL.

tools/errorgen reads ErrorConstants.xml and generates
errorconstants.{h,cpp}.

throwError() takes errorID from errorconstants.h, retrieves the error
message, constructs an Error object and throws it.

TODO:
- Run make errorgen automatically by make
- Tamarin has error message translations for several languages,
  copy them, too.
  • Loading branch information...
commit d61e5e39a5a9be213fba3b098383d111f0f92037 1 parent 9231bb4
@aajanki aajanki authored
Showing with 1,465 additions and 159 deletions.
  1. +673 −0 resources/ErrorConstants.xml
  2. +1 −0  src/CMakeLists.txt
  3. +20 −20 src/asobject.cpp
  4. +3 −0  src/asobject.h
  5. +197 −0 src/errorconstants.cpp
  6. +203 −0 src/errorconstants.h
  7. +17 −14 src/scripting/abc_opcodes.cpp
  8. +7 −3 src/scripting/argconv.h
  9. +2 −1  src/scripting/class.cpp
  10. +19 −15 src/scripting/flash/display/BitmapData.cpp
  11. +7 −7 src/scripting/flash/display/flashdisplay.cpp
  12. +1 −1  src/scripting/flash/geom/flashgeom.cpp
  13. +7 −7 src/scripting/flash/net/flashnet.cpp
  14. +2 −2 src/scripting/flash/text/flashtext.cpp
  15. +2 −1  src/scripting/flash/text/flashtextengine.cpp
  16. +21 −21 src/scripting/flash/utils/flashutils.cpp
  17. +3 −3 src/scripting/toplevel/Array.cpp
  18. +53 −3 src/scripting/toplevel/Error.cpp
  19. +14 −0 src/scripting/toplevel/Error.h
  20. +4 −2 src/scripting/toplevel/Math.cpp
  21. +4 −4 src/scripting/toplevel/Number.cpp
  22. +1 −1  src/scripting/toplevel/RegExp.cpp
  23. +28 −20 src/scripting/toplevel/Vector.cpp
  24. +24 −24 src/scripting/toplevel/XML.cpp
  25. +6 −2 src/scripting/toplevel/XMLList.cpp
  26. +13 −8 src/scripting/toplevel/toplevel.cpp
  27. +133 −0 tools/errorgen
View
673 resources/ErrorConstants.xml
@@ -0,0 +1,673 @@
+<?xml version='1.0' encoding='utf-8' standalone='no' ?>
+<!-- -*- Mode: xml; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- -->
+<!-- vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) -->
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<errors> This table contains all of the error messages generated by core
+ avmplus. This will likely be replaced by a resource table
+ for easy localization.
+ %o = ScriptObject*
+ %t = Traits*
+ %m = MethodInfo*
+ %n = Multiname (name portion only)
+ %N = Multiname (namespace portion only)
+ %a = Atom
+ %d = int
+ %f = double
+ %S = Stringp
+ %s = char*
+
+ <error id="1000" label="kOutOfMemoryError">The system is out of memory.
+<description><![CDATA[
+ Flash Player needs more memory to compile your code than your system has available.
+ Close some of the applications or processes running on your system.
+ ]]></description></error>
+
+ <error id="1001" label="kNotImplementedError">The method %1 is not implemented.</error>
+ <error id="1002" label="kInvalidPrecisionError">Number.toPrecision has a range of 1 to 21. Number.toFixed and Number.toExponential have a range of 0 to 20. Specified value is not within expected range.
+<description><![CDATA[
+ You specified a value that is not within the expected range of the <code>precision</code> argument. Number.toPrecision has a range of 1 to 21. Number.toFixed and Number.toExponential have a range of 0 to 20.
+ ]]></description></error>
+
+ <error id="1003" label="kInvalidRadixError">The radix argument must be between 2 and 36; got %1.
+ <description><![CDATA[
+ You passed a value less than 2 or greater than 36 for the <code>radix</code> argument of a method or property.
+ Pass a value between 2 and 36 as a <code>radix</code> argument.
+ ]]></description> </error>
+ <error id="1004" label="kInvokeOnIncompatibleObjectError">Method %1 was invoked on an incompatible object.
+<description><![CDATA[
+ You tried to call a method that is not available to the specified object. This error occurs when
+ you have copied a prototype function from one object to another, and then invoked it, but the
+ target object is not the same type as the original object. Ensure that the target object and
+ original object are the same type. See the ECMAScript Language Specification, 3rd Edition, Chapter 15 for more details.
+ ]]></description></error>
+
+ <!-- ISSUE jsshell reports "invalid array length" -->
+<error id="1005" label="kArrayIndexNotIntegerError">Array index is not a positive integer (%1).
+<description><![CDATA[
+ You tried to access a member of an array using an index value that is not a positive integer. Pass only positive integers as index values for arrays.
+ ]]></description></error>
+
+
+<error id="1006" label="kCallOfNonFunctionError">%1 is not a function.
+<description><![CDATA[
+ This error occurs when you attempt to call a function that does not exist.
+ Make sure you are calling the correct function, and that the API has
+ not changed from ActionScript 2.0. Also, make sure you are using the correct
+ object. For example, you will see this error when you use the following code
+ (because the last line mistakenly calls the variable <code>big</code> instead
+ of <code>blg</code>):
+
+ <pre><code>var blg:String = "foo";
+var big:Sprite = new Sprite();
+var error:int = big.length(); </code></pre>
+ ]]></description></error>
+ <error id="1007" label="kConstructOfNonFunctionError">Instantiation attempted on a non-constructor.</error>
+ <error id="1008" label="kAmbiguousBindingError">%1 is ambiguous; Found more than one matching binding.</error>
+ <error id="1009" label="kConvertNullToObjectError">Cannot access a property or method of a null object reference.
+<description><![CDATA[
+ An object that evaluates to <code>null</code> can have no properties. This error can occur in some unexpected
+ (though valid) situations. For example, consider the following code, which creates a Sprite
+ object. Because this Sprite object is never added to the display list (through the
+ <code>addChild()</code> method of a DisplayObjectContainer object), its <code>stage</code>
+ property is set to <code>null</code>. Thus, the example generates this error because Sprite object's <code>stage</code> property
+ cannot have any properties:
+
+ <pre><code>import flash.display.Sprite;
+var sprite1:Sprite = new Sprite();
+var q:String = sprite1.stage.quality;</code></pre>
+ ]]></description></error>
+
+ <error id="1010" label="kConvertUndefinedToObjectError">A term is undefined and has no properties.
+<description><![CDATA[
+ This error can occur if you try to access a property of an object that does not exist. For example:
+ <pre><code>var obj:Object = new Object();
+obj.a = "foo";
+trace(obj.b.prop);</code></pre>
+
+ <p>You can also see this error because of a misspelling, for example in the following, where
+ <code>mc</code> represents a MovieClip object in the display list, and the <code>stage</code>
+ property is misspelled with a capital S (it should be <code>stage</code>):</p>
+
+ <pre><code>trace(mc.Stage.quality);</code></pre>
+
+
+ ]]></description></error>
+ <error id="1011" label="kIllegalOpcodeError">Method %1 contained illegal opcode %2 at offset %3.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1012" label="kLastInstExceedsCodeSizeError">The last instruction exceeded code size.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1013" label="kFindVarWithNoScopeError">Cannot call OP_findproperty when scopeDepth is 0.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1014" label="kClassNotFoundError">Class %1 could not be found.</error>
+ <error id="1015" label="kIllegalSetDxns">Method %1 cannot set default xml namespace
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1016" label="kDescendentsError">Descendants operator (..) not supported on type %1.</error>
+ <error id="1017" label="kScopeStackOverflowError">Scope stack overflow occurred.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1018" label="kScopeStackUnderflowError">Scope stack underflow occurred.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1019" label="kGetScopeObjectBoundsError">Getscopeobject %1 is out of bounds.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+ <error id="1020" label="kCannotFallOffMethodError">Code cannot fall off the end of a method.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1021" label="kInvalidBranchTargetError">At least one branch target was not on a valid instruction in the method.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1022" label="kIllegalVoidError">Type void may only be used as a function return type.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1023" label="kStackOverflowError">Stack overflow occurred.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1024" label="kStackUnderflowError">Stack underflow occurred.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1025" label="kInvalidRegisterError">An invalid register %1 was accessed.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1026" label="kSlotExceedsCountError">Slot %1 exceeds slotCount=%2 of %3.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1027" label="kMethodInfoExceedsCountError">Method_info %1 exceeds method_count=%2.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1028" label="kDispIdExceedsCountError">Disp_id %1 exceeds max_disp_id=%2 of %3.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1029" label="kDispIdUndefinedError">Disp_id %1 is undefined on %2.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1030" label="kStackDepthUnbalancedError">Stack depth is unbalanced. %1 != %2.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1031" label="kScopeDepthUnbalancedError">Scope depth is unbalanced. %1 != %2.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1032" label="kCpoolIndexRangeError">Cpool index %1 is out of range %2.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1033" label="kCpoolEntryWrongTypeError">Cpool entry %1 is wrong type.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1034" label="kCheckTypeFailedError">Type Coercion failed: cannot convert %1 to %2.</error>
+
+ <error id="1035" label="kIllegalSuperCallError">Illegal super expression found in method %1.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <!-- <error id="1036" label="kUncaughtExceptionWarning">The VM exited due to an uncaught exception.</error> -->
+
+ <error id="1037" label="kCannotAssignToMethodError">Cannot assign to a method %1 on %2.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+
+<error id="1038" label="kRedefinedError">%1 is already defined.
+<description><![CDATA[
+ You cannot declare a variable or function with the same identifier name more than once
+ within the same scope.
+ In ActionScript 3.0, different code blocks (such as those used in two <code>for</code> loops
+ in the same <code>function</code> definition) are considered to be in the same scope.
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1039" label="kCannotVerifyUntilReferencedError">Cannot verify method until it is referenced.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1040" label="kCantUseInstanceofOnNonObjectError">The right-hand side of instanceof must be a class or function.
+<description><![CDATA[
+ The expression on the right side of the <code>instanceof</code> operator must be a class or function.
+ ]]></description></error>
+ <error id="1041" label="kIsTypeMustBeClassError">The right-hand side of operator must be a class.
+<description><![CDATA[
+ The expression on the right side of the <code>is</code> operator must be a class.
+ ]]></description></error>
+ <error id="1042" label="kInvalidMagicError">Not an ABC file. major_version=%1 minor_version=%2.
+<description><![CDATA[
+You are attempting to use an invalid file with the player: the tool that generates the SWF may be out of date or the SWF itself may be corrupt.
+ ]]></description></error>
+ <error id="1043" label="kInvalidCodeLengthError">Invalid code_length=%1.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1044" label="kInvalidMethodInfoFlagsError">MethodInfo-%1 unsupported flags=%2.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+
+ <error id="1045" label="kUnsupportedTraitsKindError">Unsupported traits kind=%1.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1046" label="kMethodInfoOrderError">MethodInfo-%1 referenced before definition.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1047" label="kMissingEntryPointError">No entry point was found.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+ <!--<error id="1048" label="kNativeMethodNotFoundError">Native method not found: %a.</error>-->
+
+ <error id="1049" label="kPrototypeTypeError">Prototype objects must be vanilla Objects.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1050" label="kConvertToPrimitiveError">Cannot convert %1 to primitive.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1051" label="kIllegalEarlyBindingError">Illegal early binding access to %1.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1052" label="kInvalidURIError">Invalid URI passed to %1 function.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1053" label="kIllegalOverrideError">Illegal override of %1 in %2.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1054" label="kIllegalExceptionHandlerError">Illegal range or target offsets in exception handler.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+ <!-- obsolete
+ <error id="1055" label="kHasNoPropertiesTypeError">%S has no properties</error>
+ -->
+ <error id="1056" label="kWriteSealedError">Cannot create property %1 on %2.
+<description><![CDATA[
+ You are trying to assign a value to a nonexistent property on an instance of a non-dynamic
+ class. This is only possible for instances of dynamic classes]]></description></error>
+
+ <error id="1057" label="kIllegalSlotError">%1 can only contain methods.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1058" label="kIllegalOperandTypeError">Illegal operand type: %1 must be %2.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1059" label="kClassInfoOrderError">ClassInfo-%1 is referenced before definition.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1060" label="kClassInfoExceedsCountError">ClassInfo %1 exceeds class_count=%2.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+
+<error id="1061" label="kNumberOutOfRangeError">The value %1 cannot be converted to %2 without losing precision.
+<description><![CDATA[
+
+ This error appears if you attempt to assign a decimal number to a property that has data type
+ int.
+
+ <p>This error also appears for out-of-range assignments, such as the following:</p>
+
+ <pre><code>var m0:int = 2147483648; // int.MAX_VALUE == 2147483647</code></pre>
+ <p>You can also see this error when using the bitwise left shift operator (&lt&lt).
+ For example, consider the following code:</p>
+
+ <pre><code>var m0:uint = 0xFF;
+var m1:uint = m0&lt&lt24;</code></pre>
+
+ <p>The result of left shift operator (&lt&lt) is interpreted as a 32-bit two's complement number
+ with sign. In the example, the result is a negative value, which causes the error when assigned
+ to the uint typed property. A workaround is the following:</p>
+
+ <pre><code>var m0:uint = 0xFF;
+var m1:uint = uint(m0&lt;&lt;24);</code></pre>
+
+ ]]></description></error>
+ <!--<error id="1062" label="kPackageCircularityError">Package %a imported while being defined</error>-->
+ <error id="1063" label="kWrongArgumentCountError">Argument count mismatch on %1. Expected %2, got %3.</error>
+ <error id="1064" label="kCannotCallMethodAsConstructor">Cannot call method %1 as constructor.
+ <description><![CDATA[
+ Extracted methods are permanently bound to the object they are extracted from.
+ Therefore, they can not later be called as a constructor. For example, the following
+ creates function <code>f()</code> in Class A:
+ <pre><code>class A {
+ function f() {}
+ }</code></pre>
+ In the following code, extracting the function causes no error. However, creating
+ a new instance of the function causes an error.
+ <pre><code>var a = new A()
+ var m = a.f // extract f, don't call it
+ m() // same as a.f()
+ new m() // causes this error</code></pre>
+
+ ]]></description></error>
+ <error id="1065" label="kUndefinedVarError">Variable %1 is not defined.
+ <description><![CDATA[
+ You are using an undefined lexical reference. For example, in the following statements, the
+ statement <code>trace(x)</code> generates an error because <code>x</code> is undefined. However, the
+ statement <code>trace(y)</code> doesn't generate an error because <code>y</code> is defined:
+ <pre><code>trace("hello world")
+ trace(x) // x is undefined
+ var y
+ trace(y) // No error, y is defined.</code></pre>
+ ]]></description></error>
+ <error id="1066" label="kFunctionConstructorError">The form function('function body') is not supported.
+ <description><![CDATA[
+ Unlike JavaScript, Flash does not compile code on-the-fly using <code>eval()</code> and
+ <code>function()</code>. Thus, calling these as a constructor in ActionScript 3.0 generates this error.
+ ]]></description></error>
+
+<error id="1067" label="kIllegalNativeMethodBodyError">Native method %1 has illegal method body.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+
+<error id="1068" label="kCannotMergeTypesError">%1 and %2 cannot be reconciled.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1069" label="kReadSealedError">Property %1 not found on %2 and there is no default value.
+ <description><![CDATA[
+ You are referencing an undefined property on a non-dynamic class instance. For example, the following generates this error when it references property
+ <code>x</code>, which is not defined and cannot be created dynamically:
+ <pre><code>class A {} // sealed class, not dynamic
+ trace(new A().x) // no property x defined on A, and A is not dynamic</code></pre>
+ ]]></description></error>
+ <error id="1070" label="kCallNotFoundError">Method %1 not found on %2
+ <description><![CDATA[
+ You are using a <code>super</code> statement to call a function, but the function doesn't exist in the super class.
+ For example, the following code generates the error: <pre><code>class A() {}
+class B extends A {
+ function f() { trace(super.f()); } // error 1070, there is no f on A
+}</code></pre>
+ ]]></description></error>
+ <error id="1071" label="kAlreadyBoundError">Function %1 has already been bound to %2.</error>
+
+<error id="1072" label="kZeroDispIdError">Disp_id 0 is illegal.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1073" label="kDuplicateDispIdError">Non-override method %1 replaced because of duplicate disp_id %2.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+<error id="1074" label="kConstWriteError">Illegal write to read-only property %1 on %2.</error>
+ <error id="1075" label="kMathNotFunctionError">Math is not a function.
+ <description><![CDATA[
+ You are trying to call <code>math()</code> as a function, but the Math class is a class with static methods.
+ ]]></description></error>
+ <error id="1076" label="kMathNotConstructorError">Math is not a constructor.
+ <description><![CDATA[
+ You can not instantiate the Math class.
+ ]]></description></error>
+
+ <error id="1077" label="kWriteOnlyError">Illegal read of write-only property %1 on %2.</error>
+ <error id="1078" label="kIllegalOpMultinameError">Illegal opcode/multiname combination: %1&lt;%2&gt;.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1079" label="kIllegalNativeMethodError">Native methods are not allowed in loaded code.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1080" label="kIllegalNamespaceError">Illegal value for namespace.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+
+ <error id="1081" label="kReadSealedErrorNs">Property %1 not found on %2 and there is no default value.</error>
+ <!--<error id="1081" label="kIllegalMultinameCallError">Illegal call to %1</error>-->
+
+ <error id="1082" label="kNoDefaultNamespaceError">No default namespace has been set.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1083" label="kXMLPrefixNotBound">The prefix "%1" for element "%2" is not bound.
+<description><![CDATA[
+ An attribute name or element name has a prefix but no matching namespace was
+ found. This statement generates an error because there is no <code>foo</code>
+ namespace to match <code>foo:x</code>:<pre/>&lt;foo:x xmlns:clowns='http://circuscenter.org'&gt;</pre>
+ ]]></description></error>
+
+ <error id="1084" label="kXMLBadQName">Element or attribute ("%1") does not match QName production: QName::=(NCName':')?NCName.
+<description><![CDATA[
+ You have <code>foo: </code> or <code>:foo</code> as an element or attribute name, but there is nothing
+ on the other side of the colon.
+ ]]></description></error>
+ <error id="1085" label="kXMLUnterminatedElementTag">The element type "%1" must be terminated by the matching end-tag "&lt;/%2&gt;".</error>
+ <error id="1086" label="kXMLOnlyWorksWithOneItemLists">The %1 method only works on lists containing one item.
+<description><![CDATA[
+ The XMLList class propagates the XML-specific functions to one child if it has only one
+ item in its list. If more than one item is in the list, the routines fail with this
+ error. This happens for the following XMLList functions that mimic XML functions:
+ <p><code>addNamespace</code>, <code>appendChild</code>, <code>childIndex</code>,
+ <code>inScopeNamespaces</code>, <code>insertChildAfter</code>, <code>insertChildBefore</code>,
+ <code>name</code>, <code>namespace</code>, <code>localName</code>, <code>namespaceDeclarations</code>,
+ <code>nodeKind</code>, <code>prependChild</code>, <code>removeNamespace</code>, <code>replace</code>,
+ <code>setChildren</code>, <code>setLocalName</code>, <code>setName</code>, and <code>setNamespace.
+
+ ]]></description></error>
+ <error id="1087" label="kXMLAssignmentToIndexedXMLNotAllowed">Assignment to indexed XML is not allowed.</error>
+ <error id="1088" label="kXMLMarkupMustBeWellFormed">The markup in the document following the root element must be well-formed.
+<description><![CDATA[
+ These are possible causes of this error:
+ <ul>
+ <li>Parsing an XMLList style object as XML</li>
+ <li>Misbalanced strings</li>
+ </ul>
+ ]]></description></error>
+
+ <error id="1089" label="kXMLAssigmentOneItemLists">Assignment to lists with more than one item is not supported.</error>
+ <error id="1090" label="kXMLMalformedElement">XML parser failure: element is malformed.
+<description><![CDATA[
+ An element name is malformed. This example of an element name is malformed because a
+ trailing right angle bracket <code>></code> is missing:
+
+ <pre>&lt;a/&gt;&lt;b&gt;&lt;/b</pre> ]]></description></error>
+
+ <error id="1091" label="kXMLUnterminatedCData">XML parser failure: Unterminated CDATA section.</error>
+ <error id="1092" label="kXMLUnterminatedXMLDecl">XML parser failure: Unterminated XML declaration.</error>
+ <error id="1093" label="kXMLUnterminatedDocTypeDecl">XML parser failure: Unterminated DOCTYPE declaration.</error>
+ <error id="1094" label="kXMLUnterminatedComment">XML parser failure: Unterminated comment.</error>
+ <error id="1095" label="kXMLUnterminatedAttribute">XML parser failure: Unterminated attribute.</error>
+ <error id="1096" label="kXMLUnterminatedElement">XML parser failure: Unterminated element.</error>
+ <error id="1097" label="kXMLUnterminatedProcessingInstruction">XML parser failure: Unterminated processing instruction.</error>
+ <error id="1098" label="kXMLNamespaceWithPrefixAndNoURI">Illegal prefix %1 for no namespace.
+<description><![CDATA[
+ The namespace constructor throws this error if you try to pass in an empty URI with a
+ non-empty prefix as in this example:
+
+<pre>ns = new Namespace ("prefix", "");
+ ]]></description></error>
+
+ <!--<error id="1099" label="kNullArgumentError">Argument %s cannot be null.</error>-->
+ <error id="1100" label="kRegExpFlagsArgumentError">Cannot supply flags when constructing one RegExp from another.
+ <description><![CDATA[
+ Creating a new regular expression from an existing one also copies its flags. To create a regular expression with
+ different flags, use the <code>new</code> operator and set the flags as desired. For example, this statement
+ creates a regular expression and specifies flag settings:
+ <pre><code>var re:RegExp = new RegExp("ali", /s)</code></pre>
+ Alternatively, this statement creates a regular expression that has the same flags as re:
+ <pre><code>var re2:RegExp = new RegExp(re, ...)</code></pre> ]]></description></error>
+
+ <error id="1101" label="kNoScopeError">Cannot verify method %1 with unknown scope.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1102" label="kIllegalDefaultValue">Illegal default value for type %1.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1103" label="kCannotExtendFinalClass">Class %1 cannot extend final base class.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1104" label="kXMLDuplicateAttribute">Attribute "%1" was already specified for element "%2".</error>
+ <!--<error id="1105" label="kStringIndexOutOfBoundsError">The string index %d is out of bounds; must be in range %d to %d.</error>-->
+ <!--<error id="1106" label="kInvalidRangeError">The range specified is invalid.</error>-->
+ <error id="1107" label="kCorruptABCError">The ABC data is corrupt, attempt to read out of bounds.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1108" label="kInvalidBaseClassError">The OP_newclass opcode was used with the incorrect base class.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1109" label="kDanglingFunctionError">Attempt to directly call unbound function %1 from method %2.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1110" label="kCannotExtendError">%1 cannot extend %2.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1111" label="kCannotImplementError">%1 cannot implement %2.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1112" label="kCoerceArgumentCountError">Argument count mismatch on class coercion. Expected 1, got %1.</error>
+ <error id="1113" label="kInvalidNewActivationError">OP_newactivation used in method without NEED_ACTIVATION flag.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1114" label="kNoGlobalScopeError">OP_getglobalslot or OP_setglobalslot used with no global scope.
+<description><![CDATA[
+ See the <a href="#note">note</a> at the bottom of this table.&#42;
+ ]]></description></error>
+
+ <error id="1115" label="kNotConstructorError">%1 is not a constructor.</error>
+ <error id="1116" label="kApplyError">second argument to Function.prototype.apply must be an array.</error>
+ <error id="1117" label="kXMLInvalidName">Invalid XML name: %1.</error>
+ <error id="1118" label="kXMLIllegalCyclicalLoop">Illegal cyclical loop between nodes.</error>
+ <error id="1119" label="kDeleteTypeError">Delete operator is not supported with operand of type %1.</error>
+ <error id="1120" label="kDeleteSealedError">Cannot delete property %1 on %2.</error>
+ <error id="1121" label="kDuplicateMethodBodyError">Method %1 has a duplicate method body.</error>
+ <error id="1122" label="kIllegalInterfaceMethodBodyError">Interface method %1 has illegal method body.</error>
+ <error id="1123" label="kFilterError">Filter operator not supported on type %1.</error>
+ <error id="1124" label="kInvalidHasNextError">OP_hasnext2 requires object and index to be distinct registers.</error>
+ <error id="1125" label="kOutOfRangeError">The index %1 is out of range %2.</error>
+ <error id="1126" label="kVectorFixedError">Cannot change the length of a fixed Vector.</error>
+ <error id="1127" label="kTypeAppOfNonParamType">Type application attempted on a non-parameterized type.</error>
+ <error id="1128" label="kWrongTypeArgCountError">Incorrect number of type parameters for %1. Expected %2, got %3.</error>
+ <error id="1129" label="kJSONCyclicStructure">Cyclic structure cannot be converted to JSON string.</error>
+ <!-- id 1130 was allocated and later became unnecessary. -->
+ <error id="1131" label="kJSONInvalidReplacer">Replacer argument to JSON stringifier must be an array or a two parameter function.</error>
+ <error id="1132" label="kJSONInvalidParseInput">Invalid JSON parse input.</error>
+
+ <!-- The following errors are specific to the AVM2 command-line shell.-->
+ <error id="1500" hidden="true" label="kFileOpenError">Error occurred opening file %1.</error>
+ <error id="1501" hidden="true" label="kFileWriteError">Error occurred writing to file %1.
+ <description><![CDATA[
+ The file you are writing to cannot be opened. Possibly the filename contains an error, the file is read-only, or
+ you do not have access privileges.
+ ]]></description>
+ </error>
+ <error id="1502" label="kScriptTimeoutError">A script has executed for longer than the default timeout period of 15 seconds.
+ <description><![CDATA[
+ A script executed after the timeout period. (The default timeout period is 15 seconds.) After this error occurs, the
+ script can continue to execute for 15 seconds more, after which the script terminates and throws run-time error number 1503 (A script failed to exit after 30 seconds and was terminated.)
+ ]]></description>
+ </error>
+ <error id="1503" label="kScriptTerminatedError">A script failed to exit after 30 seconds and was terminated.
+ <description><![CDATA[
+ The script was still executing after 30 seconds. Flash Player first throws run-time error number 1502 (A script has executed for longer than the default timeout period of 15 seconds.) if the script executed more than 15
+ seconds, which is the default timeout period. This error occurs 15 seconds after Error 1502 occurs.
+ ]]></description></error>
+ <error id="1504" hidden="true" label="kEndOfFileError">End of file.
+ <description><![CDATA[
+ Flash Player unexpectedly encountered the end of the file. Possibly the file was not saved correctly or Flash Player expected more data
+ in the file.
+ ]]></description>
+ </error>
+ <error id="1505" hidden="true" label="kStringIndexOutOfBoundsError">The string index %1 is out of bounds; must be in range %2 to %3.</error>
+ <error id="1506" hidden="true" label="kInvalidRangeError">The specified range is invalid.
+ <description><![CDATA[
+ The method's <code>start</code> parameter is greater than its <code>end</code> parameter.
+ ]]></description></error>
+ <error id="1507" label="kNullArgumentError">Argument %1 cannot be null.</error>
+ <error id="1508" label="kInvalidArgumentError">The value specified for argument %1 is invalid.
+ <description><![CDATA[
+ You are possibly trying to pass the wrong data type. For example, the code
+ <pre><code>public function doSomething(const:int):void {
+ }
+ this ["doSomething"] ("str")</code></pre>
+ generates an error at runtime because <code>doSomething</code> is cast as an int data type. ]]></description></error>
+
+ <error id="1510" label="kArrayFilterNonNullObjectError">When the callback argument is a method of a class, the optional this argument must be null.</error>
+ <error id="1511" label="kWorkerAlreadyStarted">Worker is already started.</error>
+ <error id="1512" label="kFailedWorkerCannotBeRestarted">Starting a worker that already failed is not supported.</error>
+ <error id="1513" label="kWorkerTerminated">Worker has terminated."</error>
+ <error id="1514" label="kMutextNotLocked">unlock() with no preceding matching lock().</error>
+ <error id="1515" label="kConditionInvalidTimeout">Invalid condition timeout value: %1.</error>
+ <error id="1516" label="kConditionCannotNotify">Condition cannot notify if associated mutex is not owned.</error>
+ <error id="1517" label="kConditionCannotNotifyAll">Condition cannot notifyAll if associated mutex is not owned.</error>
+ <error id="1518" label="kConditionCannotWait">Condition cannot wait if associated mutex is not owned.</error>
+ <error id="1519" label="kConditionCannotBeInitialized">Condition cannot be initialized.</error>
+ <error id="1520" label="kMutexCannotBeInitialized">Mutex cannot be initialized.</error>
+ <error id="1521" label="kWorkerIllegalCallToStart">Only the worker's parent may call start.</error>
+
+ <error id="2004" label="kInvalidParamError">One of the parameters is invalid.</error>
+ <error id="2006" label="kParamRangeError">The supplied index is out of bounds.</error>
+ <error id="2007" label="kNullPointerError">Parameter %1 must be non-null.</error>
+ <error id="2008" label="kInvalidEnumError">Parameter %1 must be one of the accepted values.</error>
+ <error id="2012" label="kCantInstantiateError">%1 class cannot be instantiated.</error>
+ <error id="2030" label="kEOFError">End of file was encountered.</error>
+ <error id="2058" label="kCompressedDataError">There was an error decompressing the data.</error>
+ <error id="2085" label="kEmptyStringError">Parameter %1 must be non-empty string.</error>
+ <error id="2088" label="kProxyGetPropertyError">The Proxy class does not implement getProperty. It must be overridden by a subclass.</error>
+ <error id="2089" label="kProxySetPropertyError">The Proxy class does not implement setProperty. It must be overridden by a subclass.</error>
+ <error id="2090" label="kProxyCallPropertyError">The Proxy class does not implement callProperty. It must be overridden by a subclass.</error>
+ <error id="2091" label="kProxyHasPropertyError">The Proxy class does not implement hasProperty. It must be overridden by a subclass.</error>
+ <error id="2092" label="kProxyDeletePropertyError">The Proxy class does not implement deleteProperty. It must be overridden by a subclass.</error>
+ <error id="2093" label="kProxyGetDescendantsError">The Proxy class does not implement getDescendants. It must be overridden by a subclass.</error>
+ <error id="2105" label="kProxyNextNameIndexError">The Proxy class does not implement nextNameIndex. It must be overridden by a subclass.</error>
+ <error id="2106" label="kProxyNextNameError">The Proxy class does not implement nextName. It must be overridden by a subclass.</error>
+ <error id="2107" label="kProxyNextValueError">The Proxy class does not implement nextValue. It must be overridden by a subclass.</error>
+ <error id="2108" label="kInvalidArrayLengthError">The value %1 is not a valid Array length.</error>
+ <error id="2173" label="kReadExternalNotImplementedError">Unable to read object in stream. The class %1 does not implement flash.utils.IExternalizable but is aliased to an externalizable class.</error>
+
+</errors>
View
1  src/CMakeLists.txt
@@ -31,6 +31,7 @@ SET(LIBSPARK_SOURCES
threading.cpp
timer.cpp
tiny_string.cpp
+ errorconstants.cpp
backends/audio.cpp
backends/builtindecoder.cpp
backends/config.cpp
View
40 src/asobject.cpp
@@ -28,6 +28,7 @@
#include "scripting/toplevel/Date.h"
#include "scripting/toplevel/XML.h"
#include "scripting/toplevel/XMLList.h"
+#include "scripting/toplevel/Error.h"
using namespace lightspark;
using namespace std;
@@ -286,7 +287,7 @@ _R<ASObject> ASObject::call_valueOf()
_NR<ASObject> o=getVariableByMultiname(valueOfName,SKIP_IMPL);
if (!o->is<IFunction>())
- throw Class<TypeError>::getInstanceS("Error #1006: Call attempted on an object that is not a function.");
+ throwError<TypeError>(kCallOfNonFunctionError, valueOfName.normalizedName());
IFunction* f=o->as<IFunction>();
incRef();
@@ -523,10 +524,7 @@ void ASObject::setVariableByMultiname(const multiname& name, ASObject* o, CONST_
if (obj && (obj->kind == CONSTANT_TRAIT && allowConst==CONST_NOT_ALLOWED))
{
- tiny_string err=tiny_string("Error #1074: Illegal write to read-only property ")+name.normalizedName();
- if(classdef)
- err+=tiny_string(" on type ")+classdef->as<Class_base>()->getQualifiedClassName();
- throw Class<ReferenceError>::getInstanceS(err);
+ throwError<ReferenceError>(kConstWriteError, name.normalizedName(), classdef->as<Class_base>()->getQualifiedClassName());
}
if(!obj && cls)
{
@@ -537,8 +535,7 @@ void ASObject::setVariableByMultiname(const multiname& name, ASObject* o, CONST_
obj=cls->findBorrowedSettable(name,&has_getter);
if(obj && cls->isFinal && !obj->setter)
{
- tiny_string err=tiny_string("Error #1037: Cannot assign to a method ")+name.normalizedName()+tiny_string(" on ")+cls->getQualifiedClassName();
- throw Class<ReferenceError>::getInstanceS(err);
+ throwError<ReferenceError>(kCannotAssignToMethodError, name.normalizedName(), cls ? cls->getQualifiedClassName() : "");
}
}
@@ -548,20 +545,13 @@ void ASObject::setVariableByMultiname(const multiname& name, ASObject* o, CONST_
{
if(has_getter) // Is this a read-only property?
{
- tiny_string err=tiny_string("Error #1074: Illegal write to read-only property ")+name.normalizedName();
- if(cls)
- err+=tiny_string(" on type ")+cls->getQualifiedClassName();
- throw Class<ReferenceError>::getInstanceS(err);
+ throwError<ReferenceError>(kConstWriteError, name.normalizedName(), cls ? cls->getQualifiedClassName() : "");
}
// Properties can not be added to a sealed class
if (cls && cls->isSealed)
{
- tiny_string err=tiny_string("Error #1056: Cannot create property ") +
- name.normalizedName() +
- tiny_string(" on ") +
- cls->getQualifiedClassName();
- throw Class<ReferenceError>::getInstanceS(err);
+ throwError<ReferenceError>(kWriteSealedError, name.normalizedName(), cls->getQualifiedClassName());
}
//Create a new dynamic variable
@@ -732,7 +722,7 @@ variable* variables_map::findObjVar(const multiname& mname, TRAIT_KIND createKin
if(createKind == DYNAMIC_TRAIT)
{
if(!mname.ns.begin()->hasEmptyName())
- throw Class<ReferenceError>::getInstanceS("Error #1056: Trying to create a dynamic variable with namespace != \"\"");
+ throwError<ReferenceError>(kWriteSealedError, mname.normalizedName(), "" /* TODO: class name */);
var_iterator inserted=Variables.insert(
make_pair(varName(name,mname.ns[0]),variable(createKind))).first;
return &inserted->second;
@@ -1027,7 +1017,7 @@ _NR<ASObject> ASObject::executeASMethod(const tiny_string& methodName,
{
_NR<ASObject> o = getVariableByMultiname(methodName, namespaces);
if (o.isNull() || !o->is<IFunction>())
- throw Class<TypeError>::getInstanceS("Error #1006: Call attempted on an object that is not a function.");
+ throwError<TypeError>(kCallOfNonFunctionError, methodName);
IFunction* f=o->as<IFunction>();
incRef();
@@ -1351,7 +1341,7 @@ void ASObject::serialize(ByteArray* out, std::map<tiny_string, uint32_t>& string
{
//Custom serialization necessary
if(!serializeTraits)
- throw Class<TypeError>::getInstanceS("#2004: IExternalizable class must have an alias registered");
+ throwError<TypeError>(kInvalidParamError);
out->writeU29(0x7);
out->writeStringVR(stringMap, alias);
@@ -1487,7 +1477,9 @@ void ASObject::setprop_prototype(_NR<ASObject>& o)
bool has_getter = false;
variable* ret=findSettable(prototypeName,&has_getter);
if(!ret && has_getter)
- throw Class<ReferenceError>::getInstanceS("Error #1074: Illegal write to read-only property prototype");
+ throwError<ReferenceError>(kConstWriteError,
+ prototypeName.normalizedName(),
+ classdef ? classdef->as<Class_base>()->getQualifiedClassName() : "");
if(!ret)
ret = Variables.findObjVar(prototypeName,DYNAMIC_TRAIT,DECLARED_TRAIT|DYNAMIC_TRAIT);
if(ret->setter)
@@ -1498,3 +1490,11 @@ void ASObject::setprop_prototype(_NR<ASObject>& o)
else
ret->setVar(obj);
}
+
+tiny_string ASObject::getClassName()
+{
+ if (getClass())
+ return getClass()->getQualifiedClassName();
+ else
+ return "";
+}
View
3  src/asobject.h
@@ -429,6 +429,9 @@ friend class IFunction; //Needed for clone
bool has_toString();
_R<ASObject> call_toString();
+ /* Helper function for calling getClass()->getQualifiedClassName() */
+ virtual tiny_string getClassName();
+
ASFUNCTION(generator);
/* helpers for the dynamic property 'prototype' */
View
197 src/errorconstants.cpp
@@ -0,0 +1,197 @@
+/**************************************************************************
+ Lightspark, a free flash player implementation
+
+ Copyright (C) 2013 Alessandro Pignotti (a.pignotti@sssup.it)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+**************************************************************************/
+
+/* This file is generated by errorgen - DO NOT EDIT */
+
+#include <initializer_list>
+#include "errorconstants.h"
+#include "compat.h"
+
+namespace lightspark
+{
+
+const std::map<int, const char *> errorMessages = {
+ {kOutOfMemoryError, _("The system is out of memory.")},
+ {kNotImplementedError, _("The method %1 is not implemented.")},
+ {kInvalidPrecisionError, _("Number.toPrecision has a range of 1 to 21. Number.toFixed and Number.toExponential have a range of 0 to 20. Specified value is not within expected range.")},
+ {kInvalidRadixError, _("The radix argument must be between 2 and 36; got %1.")},
+ {kInvokeOnIncompatibleObjectError, _("Method %1 was invoked on an incompatible object.")},
+ {kArrayIndexNotIntegerError, _("Array index is not a positive integer (%1).")},
+ {kCallOfNonFunctionError, _("%1 is not a function.")},
+ {kConstructOfNonFunctionError, _("Instantiation attempted on a non-constructor.")},
+ {kAmbiguousBindingError, _("%1 is ambiguous; Found more than one matching binding.")},
+ {kConvertNullToObjectError, _("Cannot access a property or method of a null object reference.")},
+ {kConvertUndefinedToObjectError, _("A term is undefined and has no properties.")},
+ {kIllegalOpcodeError, _("Method %1 contained illegal opcode %2 at offset %3.")},
+ {kLastInstExceedsCodeSizeError, _("The last instruction exceeded code size.")},
+ {kFindVarWithNoScopeError, _("Cannot call OP_findproperty when scopeDepth is 0.")},
+ {kClassNotFoundError, _("Class %1 could not be found.")},
+ {kIllegalSetDxns, _("Method %1 cannot set default xml namespace")},
+ {kDescendentsError, _("Descendants operator (..) not supported on type %1.")},
+ {kScopeStackOverflowError, _("Scope stack overflow occurred.")},
+ {kScopeStackUnderflowError, _("Scope stack underflow occurred.")},
+ {kGetScopeObjectBoundsError, _("Getscopeobject %1 is out of bounds.")},
+ {kCannotFallOffMethodError, _("Code cannot fall off the end of a method.")},
+ {kInvalidBranchTargetError, _("At least one branch target was not on a valid instruction in the method.")},
+ {kIllegalVoidError, _("Type void may only be used as a function return type.")},
+ {kStackOverflowError, _("Stack overflow occurred.")},
+ {kStackUnderflowError, _("Stack underflow occurred.")},
+ {kInvalidRegisterError, _("An invalid register %1 was accessed.")},
+ {kSlotExceedsCountError, _("Slot %1 exceeds slotCount=%2 of %3.")},
+ {kMethodInfoExceedsCountError, _("Method_info %1 exceeds method_count=%2.")},
+ {kDispIdExceedsCountError, _("Disp_id %1 exceeds max_disp_id=%2 of %3.")},
+ {kDispIdUndefinedError, _("Disp_id %1 is undefined on %2.")},
+ {kStackDepthUnbalancedError, _("Stack depth is unbalanced. %1 != %2.")},
+ {kScopeDepthUnbalancedError, _("Scope depth is unbalanced. %1 != %2.")},
+ {kCpoolIndexRangeError, _("Cpool index %1 is out of range %2.")},
+ {kCpoolEntryWrongTypeError, _("Cpool entry %1 is wrong type.")},
+ {kCheckTypeFailedError, _("Type Coercion failed: cannot convert %1 to %2.")},
+ {kIllegalSuperCallError, _("Illegal super expression found in method %1.")},
+ {kCannotAssignToMethodError, _("Cannot assign to a method %1 on %2.")},
+ {kRedefinedError, _("%1 is already defined.")},
+ {kCannotVerifyUntilReferencedError, _("Cannot verify method until it is referenced.")},
+ {kCantUseInstanceofOnNonObjectError, _("The right-hand side of instanceof must be a class or function.")},
+ {kIsTypeMustBeClassError, _("The right-hand side of operator must be a class.")},
+ {kInvalidMagicError, _("Not an ABC file. major_version=%1 minor_version=%2.")},
+ {kInvalidCodeLengthError, _("Invalid code_length=%1.")},
+ {kInvalidMethodInfoFlagsError, _("MethodInfo-%1 unsupported flags=%2.")},
+ {kUnsupportedTraitsKindError, _("Unsupported traits kind=%1.")},
+ {kMethodInfoOrderError, _("MethodInfo-%1 referenced before definition.")},
+ {kMissingEntryPointError, _("No entry point was found.")},
+ {kPrototypeTypeError, _("Prototype objects must be vanilla Objects.")},
+ {kConvertToPrimitiveError, _("Cannot convert %1 to primitive.")},
+ {kIllegalEarlyBindingError, _("Illegal early binding access to %1.")},
+ {kInvalidURIError, _("Invalid URI passed to %1 function.")},
+ {kIllegalOverrideError, _("Illegal override of %1 in %2.")},
+ {kIllegalExceptionHandlerError, _("Illegal range or target offsets in exception handler.")},
+ {kWriteSealedError, _("Cannot create property %1 on %2.")},
+ {kIllegalSlotError, _("%1 can only contain methods.")},
+ {kIllegalOperandTypeError, _("Illegal operand type: %1 must be %2.")},
+ {kClassInfoOrderError, _("ClassInfo-%1 is referenced before definition.")},
+ {kClassInfoExceedsCountError, _("ClassInfo %1 exceeds class_count=%2.")},
+ {kNumberOutOfRangeError, _("The value %1 cannot be converted to %2 without losing precision.")},
+ {kWrongArgumentCountError, _("Argument count mismatch on %1. Expected %2, got %3.")},
+ {kCannotCallMethodAsConstructor, _("Cannot call method %1 as constructor.")},
+ {kUndefinedVarError, _("Variable %1 is not defined.")},
+ {kFunctionConstructorError, _("The form function('function body') is not supported.")},
+ {kIllegalNativeMethodBodyError, _("Native method %1 has illegal method body.")},
+ {kCannotMergeTypesError, _("%1 and %2 cannot be reconciled.")},
+ {kReadSealedError, _("Property %1 not found on %2 and there is no default value.")},
+ {kCallNotFoundError, _("Method %1 not found on %2")},
+ {kAlreadyBoundError, _("Function %1 has already been bound to %2.")},
+ {kZeroDispIdError, _("Disp_id 0 is illegal.")},
+ {kDuplicateDispIdError, _("Non-override method %1 replaced because of duplicate disp_id %2.")},
+ {kConstWriteError, _("Illegal write to read-only property %1 on %2.")},
+ {kMathNotFunctionError, _("Math is not a function.")},
+ {kMathNotConstructorError, _("Math is not a constructor.")},
+ {kWriteOnlyError, _("Illegal read of write-only property %1 on %2.")},
+ {kIllegalOpMultinameError, _("Illegal opcode/multiname combination: %1<%2>.")},
+ {kIllegalNativeMethodError, _("Native methods are not allowed in loaded code.")},
+ {kIllegalNamespaceError, _("Illegal value for namespace.")},
+ {kReadSealedErrorNs, _("Property %1 not found on %2 and there is no default value.")},
+ {kNoDefaultNamespaceError, _("No default namespace has been set.")},
+ {kXMLPrefixNotBound, _("The prefix \"%1\" for element \"%2\" is not bound.")},
+ {kXMLBadQName, _("Element or attribute (\"%1\") does not match QName production: QName::=(NCName':')?NCName.")},
+ {kXMLUnterminatedElementTag, _("The element type \"%1\" must be terminated by the matching end-tag \"</%2>\".")},
+ {kXMLOnlyWorksWithOneItemLists, _("The %1 method only works on lists containing one item.")},
+ {kXMLAssignmentToIndexedXMLNotAllowed, _("Assignment to indexed XML is not allowed.")},
+ {kXMLMarkupMustBeWellFormed, _("The markup in the document following the root element must be well-formed.")},
+ {kXMLAssigmentOneItemLists, _("Assignment to lists with more than one item is not supported.")},
+ {kXMLMalformedElement, _("XML parser failure: element is malformed.")},
+ {kXMLUnterminatedCData, _("XML parser failure: Unterminated CDATA section.")},
+ {kXMLUnterminatedXMLDecl, _("XML parser failure: Unterminated XML declaration.")},
+ {kXMLUnterminatedDocTypeDecl, _("XML parser failure: Unterminated DOCTYPE declaration.")},
+ {kXMLUnterminatedComment, _("XML parser failure: Unterminated comment.")},
+ {kXMLUnterminatedAttribute, _("XML parser failure: Unterminated attribute.")},
+ {kXMLUnterminatedElement, _("XML parser failure: Unterminated element.")},
+ {kXMLUnterminatedProcessingInstruction, _("XML parser failure: Unterminated processing instruction.")},
+ {kXMLNamespaceWithPrefixAndNoURI, _("Illegal prefix %1 for no namespace.")},
+ {kRegExpFlagsArgumentError, _("Cannot supply flags when constructing one RegExp from another.")},
+ {kNoScopeError, _("Cannot verify method %1 with unknown scope.")},
+ {kIllegalDefaultValue, _("Illegal default value for type %1.")},
+ {kCannotExtendFinalClass, _("Class %1 cannot extend final base class.")},
+ {kXMLDuplicateAttribute, _("Attribute \"%1\" was already specified for element \"%2\".")},
+ {kCorruptABCError, _("The ABC data is corrupt, attempt to read out of bounds.")},
+ {kInvalidBaseClassError, _("The OP_newclass opcode was used with the incorrect base class.")},
+ {kDanglingFunctionError, _("Attempt to directly call unbound function %1 from method %2.")},
+ {kCannotExtendError, _("%1 cannot extend %2.")},
+ {kCannotImplementError, _("%1 cannot implement %2.")},
+ {kCoerceArgumentCountError, _("Argument count mismatch on class coercion. Expected 1, got %1.")},
+ {kInvalidNewActivationError, _("OP_newactivation used in method without NEED_ACTIVATION flag.")},
+ {kNoGlobalScopeError, _("OP_getglobalslot or OP_setglobalslot used with no global scope.")},
+ {kNotConstructorError, _("%1 is not a constructor.")},
+ {kApplyError, _("second argument to Function.prototype.apply must be an array.")},
+ {kXMLInvalidName, _("Invalid XML name: %1.")},
+ {kXMLIllegalCyclicalLoop, _("Illegal cyclical loop between nodes.")},
+ {kDeleteTypeError, _("Delete operator is not supported with operand of type %1.")},
+ {kDeleteSealedError, _("Cannot delete property %1 on %2.")},
+ {kDuplicateMethodBodyError, _("Method %1 has a duplicate method body.")},
+ {kIllegalInterfaceMethodBodyError, _("Interface method %1 has illegal method body.")},
+ {kFilterError, _("Filter operator not supported on type %1.")},
+ {kInvalidHasNextError, _("OP_hasnext2 requires object and index to be distinct registers.")},
+ {kOutOfRangeError, _("The index %1 is out of range %2.")},
+ {kVectorFixedError, _("Cannot change the length of a fixed Vector.")},
+ {kTypeAppOfNonParamType, _("Type application attempted on a non-parameterized type.")},
+ {kWrongTypeArgCountError, _("Incorrect number of type parameters for %1. Expected %2, got %3.")},
+ {kJSONCyclicStructure, _("Cyclic structure cannot be converted to JSON string.")},
+ {kJSONInvalidReplacer, _("Replacer argument to JSON stringifier must be an array or a two parameter function.")},
+ {kJSONInvalidParseInput, _("Invalid JSON parse input.")},
+ {kFileOpenError, _("Error occurred opening file %1.")},
+ {kFileWriteError, _("Error occurred writing to file %1.")},
+ {kScriptTimeoutError, _("A script has executed for longer than the default timeout period of 15 seconds.")},
+ {kScriptTerminatedError, _("A script failed to exit after 30 seconds and was terminated.")},
+ {kEndOfFileError, _("End of file.")},
+ {kStringIndexOutOfBoundsError, _("The string index %1 is out of bounds; must be in range %2 to %3.")},
+ {kInvalidRangeError, _("The specified range is invalid.")},
+ {kNullArgumentError, _("Argument %1 cannot be null.")},
+ {kInvalidArgumentError, _("The value specified for argument %1 is invalid.")},
+ {kArrayFilterNonNullObjectError, _("When the callback argument is a method of a class, the optional this argument must be null.")},
+ {kWorkerAlreadyStarted, _("Worker is already started.")},
+ {kFailedWorkerCannotBeRestarted, _("Starting a worker that already failed is not supported.")},
+ {kWorkerTerminated, _("Worker has terminated.\"")},
+ {kMutextNotLocked, _("unlock() with no preceding matching lock().")},
+ {kConditionInvalidTimeout, _("Invalid condition timeout value: %1.")},
+ {kConditionCannotNotify, _("Condition cannot notify if associated mutex is not owned.")},
+ {kConditionCannotNotifyAll, _("Condition cannot notifyAll if associated mutex is not owned.")},
+ {kConditionCannotWait, _("Condition cannot wait if associated mutex is not owned.")},
+ {kConditionCannotBeInitialized, _("Condition cannot be initialized.")},
+ {kMutexCannotBeInitialized, _("Mutex cannot be initialized.")},
+ {kWorkerIllegalCallToStart, _("Only the worker's parent may call start.")},
+ {kInvalidParamError, _("One of the parameters is invalid.")},
+ {kParamRangeError, _("The supplied index is out of bounds.")},
+ {kNullPointerError, _("Parameter %1 must be non-null.")},
+ {kInvalidEnumError, _("Parameter %1 must be one of the accepted values.")},
+ {kCantInstantiateError, _("%1 class cannot be instantiated.")},
+ {kEOFError, _("End of file was encountered.")},
+ {kCompressedDataError, _("There was an error decompressing the data.")},
+ {kEmptyStringError, _("Parameter %1 must be non-empty string.")},
+ {kProxyGetPropertyError, _("The Proxy class does not implement getProperty. It must be overridden by a subclass.")},
+ {kProxySetPropertyError, _("The Proxy class does not implement setProperty. It must be overridden by a subclass.")},
+ {kProxyCallPropertyError, _("The Proxy class does not implement callProperty. It must be overridden by a subclass.")},
+ {kProxyHasPropertyError, _("The Proxy class does not implement hasProperty. It must be overridden by a subclass.")},
+ {kProxyDeletePropertyError, _("The Proxy class does not implement deleteProperty. It must be overridden by a subclass.")},
+ {kProxyGetDescendantsError, _("The Proxy class does not implement getDescendants. It must be overridden by a subclass.")},
+ {kProxyNextNameIndexError, _("The Proxy class does not implement nextNameIndex. It must be overridden by a subclass.")},
+ {kProxyNextNameError, _("The Proxy class does not implement nextName. It must be overridden by a subclass.")},
+ {kProxyNextValueError, _("The Proxy class does not implement nextValue. It must be overridden by a subclass.")},
+ {kInvalidArrayLengthError, _("The value %1 is not a valid Array length.")},
+ {kReadExternalNotImplementedError, _("Unable to read object in stream. The class %1 does not implement flash.utils.IExternalizable but is aliased to an externalizable class.")},
+ };
+
+};
View
203 src/errorconstants.h
@@ -0,0 +1,203 @@
+/**************************************************************************
+ Lightspark, a free flash player implementation
+
+ Copyright (C) 2013 Alessandro Pignotti (a.pignotti@sssup.it)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+**************************************************************************/
+
+/* This file is generated by errorgen - DO NOT EDIT */
+
+#ifndef ERRORCONSTANTS_H
+#define ERRORCONSTANTS_H 1
+
+#include <map>
+
+namespace lightspark
+{
+
+enum
+{
+ kOutOfMemoryError = 1000,
+ kNotImplementedError = 1001,
+ kInvalidPrecisionError = 1002,
+ kInvalidRadixError = 1003,
+ kInvokeOnIncompatibleObjectError = 1004,
+ kArrayIndexNotIntegerError = 1005,
+ kCallOfNonFunctionError = 1006,
+ kConstructOfNonFunctionError = 1007,
+ kAmbiguousBindingError = 1008,
+ kConvertNullToObjectError = 1009,
+ kConvertUndefinedToObjectError = 1010,
+ kIllegalOpcodeError = 1011,
+ kLastInstExceedsCodeSizeError = 1012,
+ kFindVarWithNoScopeError = 1013,
+ kClassNotFoundError = 1014,
+ kIllegalSetDxns = 1015,
+ kDescendentsError = 1016,
+ kScopeStackOverflowError = 1017,
+ kScopeStackUnderflowError = 1018,
+ kGetScopeObjectBoundsError = 1019,
+ kCannotFallOffMethodError = 1020,
+ kInvalidBranchTargetError = 1021,
+ kIllegalVoidError = 1022,
+ kStackOverflowError = 1023,
+ kStackUnderflowError = 1024,
+ kInvalidRegisterError = 1025,
+ kSlotExceedsCountError = 1026,
+ kMethodInfoExceedsCountError = 1027,
+ kDispIdExceedsCountError = 1028,
+ kDispIdUndefinedError = 1029,
+ kStackDepthUnbalancedError = 1030,
+ kScopeDepthUnbalancedError = 1031,
+ kCpoolIndexRangeError = 1032,
+ kCpoolEntryWrongTypeError = 1033,
+ kCheckTypeFailedError = 1034,
+ kIllegalSuperCallError = 1035,
+ kCannotAssignToMethodError = 1037,
+ kRedefinedError = 1038,
+ kCannotVerifyUntilReferencedError = 1039,
+ kCantUseInstanceofOnNonObjectError = 1040,
+ kIsTypeMustBeClassError = 1041,
+ kInvalidMagicError = 1042,
+ kInvalidCodeLengthError = 1043,
+ kInvalidMethodInfoFlagsError = 1044,
+ kUnsupportedTraitsKindError = 1045,
+ kMethodInfoOrderError = 1046,
+ kMissingEntryPointError = 1047,
+ kPrototypeTypeError = 1049,
+ kConvertToPrimitiveError = 1050,
+ kIllegalEarlyBindingError = 1051,
+ kInvalidURIError = 1052,
+ kIllegalOverrideError = 1053,
+ kIllegalExceptionHandlerError = 1054,
+ kWriteSealedError = 1056,
+ kIllegalSlotError = 1057,
+ kIllegalOperandTypeError = 1058,
+ kClassInfoOrderError = 1059,
+ kClassInfoExceedsCountError = 1060,
+ kNumberOutOfRangeError = 1061,
+ kWrongArgumentCountError = 1063,
+ kCannotCallMethodAsConstructor = 1064,
+ kUndefinedVarError = 1065,
+ kFunctionConstructorError = 1066,
+ kIllegalNativeMethodBodyError = 1067,
+ kCannotMergeTypesError = 1068,
+ kReadSealedError = 1069,
+ kCallNotFoundError = 1070,
+ kAlreadyBoundError = 1071,
+ kZeroDispIdError = 1072,
+ kDuplicateDispIdError = 1073,
+ kConstWriteError = 1074,
+ kMathNotFunctionError = 1075,
+ kMathNotConstructorError = 1076,
+ kWriteOnlyError = 1077,
+ kIllegalOpMultinameError = 1078,
+ kIllegalNativeMethodError = 1079,
+ kIllegalNamespaceError = 1080,
+ kReadSealedErrorNs = 1081,
+ kNoDefaultNamespaceError = 1082,
+ kXMLPrefixNotBound = 1083,
+ kXMLBadQName = 1084,
+ kXMLUnterminatedElementTag = 1085,
+ kXMLOnlyWorksWithOneItemLists = 1086,
+ kXMLAssignmentToIndexedXMLNotAllowed = 1087,
+ kXMLMarkupMustBeWellFormed = 1088,
+ kXMLAssigmentOneItemLists = 1089,
+ kXMLMalformedElement = 1090,
+ kXMLUnterminatedCData = 1091,
+ kXMLUnterminatedXMLDecl = 1092,
+ kXMLUnterminatedDocTypeDecl = 1093,
+ kXMLUnterminatedComment = 1094,
+ kXMLUnterminatedAttribute = 1095,
+ kXMLUnterminatedElement = 1096,
+ kXMLUnterminatedProcessingInstruction = 1097,
+ kXMLNamespaceWithPrefixAndNoURI = 1098,
+ kRegExpFlagsArgumentError = 1100,
+ kNoScopeError = 1101,
+ kIllegalDefaultValue = 1102,
+ kCannotExtendFinalClass = 1103,
+ kXMLDuplicateAttribute = 1104,
+ kCorruptABCError = 1107,
+ kInvalidBaseClassError = 1108,
+ kDanglingFunctionError = 1109,
+ kCannotExtendError = 1110,
+ kCannotImplementError = 1111,
+ kCoerceArgumentCountError = 1112,
+ kInvalidNewActivationError = 1113,
+ kNoGlobalScopeError = 1114,
+ kNotConstructorError = 1115,
+ kApplyError = 1116,
+ kXMLInvalidName = 1117,
+ kXMLIllegalCyclicalLoop = 1118,
+ kDeleteTypeError = 1119,
+ kDeleteSealedError = 1120,
+ kDuplicateMethodBodyError = 1121,
+ kIllegalInterfaceMethodBodyError = 1122,
+ kFilterError = 1123,
+ kInvalidHasNextError = 1124,
+ kOutOfRangeError = 1125,
+ kVectorFixedError = 1126,
+ kTypeAppOfNonParamType = 1127,
+ kWrongTypeArgCountError = 1128,
+ kJSONCyclicStructure = 1129,
+ kJSONInvalidReplacer = 1131,
+ kJSONInvalidParseInput = 1132,
+ kFileOpenError = 1500,
+ kFileWriteError = 1501,
+ kScriptTimeoutError = 1502,
+ kScriptTerminatedError = 1503,
+ kEndOfFileError = 1504,
+ kStringIndexOutOfBoundsError = 1505,
+ kInvalidRangeError = 1506,
+ kNullArgumentError = 1507,
+ kInvalidArgumentError = 1508,
+ kArrayFilterNonNullObjectError = 1510,
+ kWorkerAlreadyStarted = 1511,
+ kFailedWorkerCannotBeRestarted = 1512,
+ kWorkerTerminated = 1513,
+ kMutextNotLocked = 1514,
+ kConditionInvalidTimeout = 1515,
+ kConditionCannotNotify = 1516,
+ kConditionCannotNotifyAll = 1517,
+ kConditionCannotWait = 1518,
+ kConditionCannotBeInitialized = 1519,
+ kMutexCannotBeInitialized = 1520,
+ kWorkerIllegalCallToStart = 1521,
+ kInvalidParamError = 2004,
+ kParamRangeError = 2006,
+ kNullPointerError = 2007,
+ kInvalidEnumError = 2008,
+ kCantInstantiateError = 2012,
+ kEOFError = 2030,
+ kCompressedDataError = 2058,
+ kEmptyStringError = 2085,
+ kProxyGetPropertyError = 2088,
+ kProxySetPropertyError = 2089,
+ kProxyCallPropertyError = 2090,
+ kProxyHasPropertyError = 2091,
+ kProxyDeletePropertyError = 2092,
+ kProxyGetDescendantsError = 2093,
+ kProxyNextNameIndexError = 2105,
+ kProxyNextNameError = 2106,
+ kProxyNextValueError = 2107,
+ kInvalidArrayLengthError = 2108,
+ kReadExternalNotImplementedError = 2173,
+};
+
+extern const std::map<int, const char *> errorMessages;
+
+};
+
+#endif /* ERRORCONSTANTS_H */
View
31 src/scripting/abc_opcodes.cpp
@@ -586,7 +586,7 @@ ASObject* ABCVm::constructFunction(call_context* th, IFunction* f, ASObject** ar
{
//See ECMA 13.2.2
if(f->inClass)
- throw Class<TypeError>::getInstanceS("Error #1064: Cannot call method as constructor");
+ throwError<TypeError>(kCannotCallMethodAsConstructor, "");
assert(f->is<SyntheticFunction>());
SyntheticFunction* sf=f->as<SyntheticFunction>();
@@ -672,7 +672,7 @@ void ABCVm::construct(call_context* th, int m)
default:
{
- throw Class<TypeError>::getInstanceS("Error #1007: Instantiation attempted on a non-constructor");
+ throwError<TypeError>(kConstructOfNonFunctionError);
}
}
@@ -685,7 +685,7 @@ void ABCVm::constructGenericType(call_context* th, int m)
{
LOG(LOG_CALLS, _("constructGenericType ") << m);
if (m != 1)
- throw Class<TypeError>::getInstanceS("Error #1128");
+ throwError<TypeError>(kWrongTypeArgCountError, "function", "1", Integer::toString(m));
ASObject** args=g_newa(ASObject*, m);
for(int i=0;i<m;i++)
args[m-i-1]=th->runtime_stack_pop();
@@ -1517,15 +1517,15 @@ bool ABCVm::isTypelate(ASObject* type, ASObject* obj)
case T_STRING:
obj->decRef();
type->decRef();
- throw Class<TypeError>::getInstanceS("Error #1009");
+ throwError<TypeError>(kConvertNullToObjectError);
case T_UNDEFINED:
obj->decRef();
type->decRef();
- throw Class<TypeError>::getInstanceS("Error #1010");
+ throwError<TypeError>(kConvertUndefinedToObjectError);
case T_CLASS:
break;
default:
- throw Class<TypeError>::getInstanceS("Error #1041");
+ throwError<TypeError>(kIsTypeMustBeClassError);
}
c=static_cast<Class_base*>(type);
@@ -1599,7 +1599,7 @@ ASObject* ABCVm::asTypelate(ASObject* type, ASObject* obj)
{
obj->decRef();
type->decRef();
- throw Class<TypeError>::getInstanceS("Error #1009: Not a type in asTypelate");
+ throwError<TypeError>(kConvertNullToObjectError);
}
Class_base* c=static_cast<Class_base*>(type);
//Special case numeric types
@@ -1714,16 +1714,17 @@ void ABCVm::constructProp(call_context* th, int n, int m)
ASObject* obj=th->runtime_stack_pop();
_NR<ASObject> o=obj->getVariableByMultiname(*name);
- name->resetNameIfObject();
if(o.isNull())
{
for(int i=0;i<m;++i)
args[i]->decRef();
obj->decRef();
- throw Class<ReferenceError>::getInstanceS("Error #1065: Variable is not defined.");
+ throwError<ReferenceError>(kUndefinedVarError, name->normalizedName());
}
+ name->resetNameIfObject();
+
LOG(LOG_CALLS,_("Constructing"));
ASObject* ret;
try
@@ -1738,7 +1739,7 @@ void ABCVm::constructProp(call_context* th, int n, int m)
ret = constructFunction(th, o->as<IFunction>(), args, m);
}
else
- throw Class<TypeError>::getInstanceS("Error #1007: Cannot construct such an object in constructProp");
+ throwError<TypeError>(kConstructOfNonFunctionError);
}
catch(ASObject* exc)
{
@@ -1851,15 +1852,17 @@ void ABCVm::getDescendants(call_context* th, int n)
}
else
{
+ tiny_string objName = obj->getClassName();
obj->decRef();
- throw Class<TypeError>::getInstanceS("Only XML and XMLList objects have descendants");
+ throwError<TypeError>(kDescendentsError, objName);
}
}
}
else
{
+ tiny_string objName = obj->getClassName();
obj->decRef();
- throw Class<TypeError>::getInstanceS("Only XML and XMLList objects have descendants");
+ throwError<TypeError>(kDescendentsError, objName);
}
XMLList* retObj=Class<XMLList>::getInstanceS(ret);
th->runtime_stack_push(retObj);
@@ -2183,7 +2186,7 @@ void ABCVm::callImpl(call_context* th, ASObject* f, ASObject* obj, ASObject** ar
else
{
f->decRef();
- throw Class<TypeError>::getInstanceS("Error #1006: Tried to call something that is not a function");
+ throwError<TypeError>(kCallOfNonFunctionError, "Object");
}
}
LOG(LOG_CALLS,_("End of call ") << m << ' ' << f);
@@ -2294,7 +2297,7 @@ bool ABCVm::instanceOf(ASObject* value, ASObject* type)
}
if(!type->is<Class_base>())
- throw Class<TypeError>::getInstanceS("Error #1040: instanceOf expects a class of function as second parameter!");
+ throwError<TypeError>(kCantUseInstanceofOnNonObjectError);
if(value->is<Class_base>())
// Classes are instance of Class and Object but not
View
10 src/scripting/argconv.h
@@ -65,7 +65,9 @@ class ArgumentConversion<Ref<T>>
{
T* o = dynamic_cast<T*>(obj);
if(!o)
- throw Class<ArgumentError>::getInstanceS("Error #1034: Wrong type");
+ throwError<ArgumentError>(kCheckTypeFailedError,
+ obj->getClassName(),
+ Class<T>::getClass()->getQualifiedClassName());
o->incRef();
return _MR(o);
}
@@ -91,7 +93,9 @@ class ArgumentConversion<NullableRef<T>>
T* o = dynamic_cast<T*>(obj);
if(!o)
- throw Class<ArgumentError>::getInstanceS("Error #1034: Wrong type");
+ throwError<ArgumentError>(kCheckTypeFailedError,
+ obj->getClassName(),
+ Class<T>::getClass()->getQualifiedClassName());
o->incRef();
return _MNR(o);
}
@@ -224,7 +228,7 @@ class ArgUnpack
template<class T> ArgUnpack& operator()(T& v)
{
if(argslen == 0)
- throw Class<ArgumentError>::getInstanceS("Error #1063: Non-optional argument missing");
+ throwError<ArgumentError>(kWrongArgumentCountError, "object", "?", "?");
v = ArgumentConversion<T>::toConcrete(args[0]);
args++;
View
3  src/scripting/class.cpp
@@ -100,7 +100,8 @@ void Class_inherit::buildInstanceTraits(ASObject* o) const
template<>
Global* Class<Global>::getInstance(bool construct, ASObject* const* args, const unsigned int argslen, Class_base* realClass)
{
- throw Class<TypeError>::getInstanceS("Error #1007: Cannot construct global object");
+ throwError<TypeError>(kConstructOfNonFunctionError);
+ return NULL;
}
void lightspark::lookupAndLink(Class_base* c, const tiny_string& name, const tiny_string& interfaceNs)
View
34 src/scripting/flash/display/BitmapData.cpp
@@ -99,7 +99,7 @@ ASFUNCTIONBODY(BitmapData,_constructor)
uint32_t fillColor;
BitmapData* th = obj->as<BitmapData>();
if(th->disposed)
- throw Class<ArgumentError>::getInstanceS("Disposed BitmapData");
+ throw Class<ArgumentError>::getInstanceS("Disposed BitmapData", 2015);
ARG_UNPACK(width, 0)(height, 0)(transparent, true)(fillColor, 0xFFFFFFFF);
ASObject::_constructor(obj,NULL,0);
@@ -169,7 +169,7 @@ ASFUNCTIONBODY(BitmapData,draw)
{
BitmapData* th = obj->as<BitmapData>();
if(th->disposed)
- throw Class<ArgumentError>::getInstanceS("Disposed BitmapData");
+ throw Class<ArgumentError>::getInstanceS("Disposed BitmapData", 2015);
_NR<ASObject> drawable;
_NR<Matrix> matrix;
@@ -181,7 +181,9 @@ ASFUNCTIONBODY(BitmapData,draw)
(clipRect, NullRef) (smoothing, false);
if(!drawable->getClass() || !drawable->getClass()->isSubClass(InterfaceClass<IBitmapDrawable>::getClass()) )
- throw Class<TypeError>::getInstanceS("Error #1034: Wrong type");
+ throwError<TypeError>(kCheckTypeFailedError,
+ drawable->getClassName(),
+ "IBitmapDrawable");
if(!ctransform.isNull() || !blendMode.isNull() || !clipRect.isNull() || smoothing)
LOG(LOG_NOT_IMPLEMENTED,"BitmapData.draw does not support many parameters");
@@ -229,7 +231,7 @@ ASFUNCTIONBODY(BitmapData,getPixel)
{
BitmapData* th = obj->as<BitmapData>();
if(th->disposed)
- throw Class<ArgumentError>::getInstanceS("Disposed BitmapData");
+ throw Class<ArgumentError>::getInstanceS("Disposed BitmapData", 2015);
int32_t x;
int32_t y;
ARG_UNPACK(x)(y);
@@ -242,7 +244,7 @@ ASFUNCTIONBODY(BitmapData,getPixel32)
{
BitmapData* th = obj->as<BitmapData>();
if(th->disposed)
- throw Class<ArgumentError>::getInstanceS("Disposed BitmapData");
+ throw Class<ArgumentError>::getInstanceS("Disposed BitmapData", 2015);
int32_t x;
int32_t y;
ARG_UNPACK(x)(y);
@@ -268,7 +270,7 @@ ASFUNCTIONBODY(BitmapData,setPixel)
{
BitmapData* th = obj->as<BitmapData>();
if(th->disposed)
- throw Class<ArgumentError>::getInstanceS("Disposed BitmapData");
+ throw Class<ArgumentError>::getInstanceS("Disposed BitmapData", 2015);
int32_t x;
int32_t y;
uint32_t color;
@@ -282,7 +284,7 @@ ASFUNCTIONBODY(BitmapData,setPixel32)
{
BitmapData* th = obj->as<BitmapData>();
if(th->disposed)
- throw Class<ArgumentError>::getInstanceS("Disposed BitmapData");
+ throw Class<ArgumentError>::getInstanceS("Disposed BitmapData", 2015);
int32_t x;
int32_t y;
uint32_t color;
@@ -296,7 +298,7 @@ ASFUNCTIONBODY(BitmapData,getRect)
{
BitmapData* th = obj->as<BitmapData>();
if(th->disposed)
- throw Class<ArgumentError>::getInstanceS("Disposed BitmapData");
+ throw Class<ArgumentError>::getInstanceS("Disposed BitmapData", 2015);
Rectangle *rect=Class<Rectangle>::getInstanceS();
rect->width=th->width;
rect->height=th->height;
@@ -307,7 +309,7 @@ ASFUNCTIONBODY(BitmapData,fillRect)
{
BitmapData* th=obj->as<BitmapData>();
if(th->disposed)
- throw Class<ArgumentError>::getInstanceS("Disposed BitmapData");
+ throw Class<ArgumentError>::getInstanceS("Disposed BitmapData", 2015);
_NR<Rectangle> rect;
uint32_t color;
ARG_UNPACK(rect)(color);
@@ -350,7 +352,7 @@ ASFUNCTIONBODY(BitmapData,copyPixels)
{
BitmapData* th=obj->as<BitmapData>();
if(th->disposed)
- throw Class<ArgumentError>::getInstanceS("Disposed BitmapData");
+ throw Class<ArgumentError>::getInstanceS("Disposed BitmapData", 2015);
_NR<BitmapData> source;
_NR<Rectangle> sourceRect;
_NR<Point> destPoint;
@@ -413,7 +415,7 @@ ASFUNCTIONBODY(BitmapData,generateFilterRect)
LOG(LOG_NOT_IMPLEMENTED,"BitmapData::generateFilterRect is just a stub");
BitmapData* th = obj->as<BitmapData>();
if(th->disposed)
- throw Class<ArgumentError>::getInstanceS("Disposed BitmapData");
+ throw Class<ArgumentError>::getInstanceS("Disposed BitmapData", 2015);
Rectangle *rect=Class<Rectangle>::getInstanceS();
rect->width=th->width;
rect->height=th->height;
@@ -424,7 +426,7 @@ ASFUNCTIONBODY(BitmapData,hitTest)
{
BitmapData* th = obj->as<BitmapData>();
if(th->disposed)
- throw Class<ArgumentError>::getInstanceS("Disposed BitmapData");
+ throw Class<ArgumentError>::getInstanceS("Disposed BitmapData", 2015);
_NR<Point> firstPoint;
uint32_t firstAlphaThreshold;
@@ -435,7 +437,9 @@ ASFUNCTIONBODY(BitmapData,hitTest)
(secondAlphaThreshold,1);
if(!secondObject->getClass() || !secondObject->getClass()->isSubClass(Class<Point>::getClass()))
- throw Class<TypeError>::getInstanceS("Error #1034: Wrong type");
+ throwError<TypeError>(kCheckTypeFailedError,
+ secondObject->getClassName(),
+ "Point");
if(!secondBitmapDataPoint.isNull() || secondAlphaThreshold!=1)
LOG(LOG_NOT_IMPLEMENTED,"BitmapData.hitTest does not expect some parameters");
@@ -453,7 +457,7 @@ ASFUNCTIONBODY(BitmapData,scroll)
{
BitmapData* th = obj->as<BitmapData>();
if(th->disposed)
- throw Class<ArgumentError>::getInstanceS("Disposed BitmapData");
+ throw Class<ArgumentError>::getInstanceS("Disposed BitmapData", 2015);
int x;
int y;
@@ -495,7 +499,7 @@ ASFUNCTIONBODY(BitmapData,clone)
{
BitmapData* th = obj->as<BitmapData>();
if(th->disposed)
- throw Class<ArgumentError>::getInstanceS("Disposed BitmapData");
+ throw Class<ArgumentError>::getInstanceS("Disposed BitmapData", 2015);
return Class<BitmapData>::getInstanceS(*th);
}
View
14 src/scripting/flash/display/flashdisplay.cpp
@@ -1735,7 +1735,7 @@ ASFUNCTIONBODY(DisplayObjectContainer,removeChild)
DisplayObject* d=Class<DisplayObject>::cast(args[0]);
d->incRef();
if(!th->_removeChild(_MR(d)))
- throw Class<ArgumentError>::getInstanceS("removeChild: child not in list");
+ throw Class<ArgumentError>::getInstanceS("removeChild: child not in list", 2025);
//As we return the child we have to incRef it
d->incRef();
@@ -1754,7 +1754,7 @@ ASFUNCTIONBODY(DisplayObjectContainer,removeChildAt)
{
Locker l(th->mutexDisplayList);
if(index>=int(th->dynamicDisplayList.size()) || index<0)
- throw Class<RangeError>::getInstanceS("removeChildAt: invalid index");
+ throw Class<RangeError>::getInstanceS("removeChildAt: invalid index", 2025);
list<_R<DisplayObject>>::iterator it=th->dynamicDisplayList.begin();
for(int32_t i=0;i<index;i++)
++it;
@@ -1832,7 +1832,7 @@ ASFUNCTIONBODY(DisplayObjectContainer,swapChildren)
std::list<_R<DisplayObject>>::iterator it1=find(th->dynamicDisplayList.begin(),th->dynamicDisplayList.end(),child1);
std::list<_R<DisplayObject>>::iterator it2=find(th->dynamicDisplayList.begin(),th->dynamicDisplayList.end(),child2);
if(it1==th->dynamicDisplayList.end() || it2==th->dynamicDisplayList.end())
- throw Class<ArgumentError>::getInstanceS("Argument is not child of this object");
+ throw Class<ArgumentError>::getInstanceS("Argument is not child of this object", 2025);
th->dynamicDisplayList.insert(it1, child2);
th->dynamicDisplayList.insert(it2, child1);
@@ -1873,7 +1873,7 @@ ASFUNCTIONBODY(DisplayObjectContainer,getChildAt)
assert_and_throw(argslen==1);
unsigned int index=args[0]->toInt();
if(index>=th->dynamicDisplayList.size())
- throw Class<RangeError>::getInstanceS("getChildAt: invalid index");
+ throw Class<RangeError>::getInstanceS("getChildAt: invalid index", 2025);
list<_R<DisplayObject>>::iterator it=th->dynamicDisplayList.begin();
for(unsigned int i=0;i<index;i++)
++it;
@@ -1893,7 +1893,7 @@ int DisplayObjectContainer::getChildIndex(_R<DisplayObject> child)
ret++;
++it;
if(it == dynamicDisplayList.end())
- throw Class<ArgumentError>::getInstanceS("getChildIndex: child not in list");
+ throw Class<ArgumentError>::getInstanceS("getChildIndex: child not in list", 2025);
}
while(1);
return ret;
@@ -2500,7 +2500,7 @@ ASFUNCTIONBODY(Graphics,drawTriangles)
if ((indices.isNull() && (vertices->size() % 6 != 0)) ||
(!indices.isNull() && (indices->size() % 3 != 0)))
{
- throw Class<ArgumentError>::getInstanceS("Error #2004");
+ throwError<ArgumentError>(kInvalidParamError);
}
unsigned int numvertices=vertices->size()/2;
@@ -2530,7 +2530,7 @@ ASFUNCTIONBODY(Graphics,drawTriangles)
}
else
{
- throw Class<ArgumentError>::getInstanceS("Error #2004");
+ throwError<ArgumentError>(kInvalidParamError);
}
th->owner->getTextureSize(&texturewidth, &textureheight);
View
2  src/scripting/flash/geom/flashgeom.cpp
@@ -977,7 +977,7 @@ ASFUNCTIONBODY(Transform,_setColorTransform)
_NR<ColorTransform> ct;
ARG_UNPACK(ct);
if (ct.isNull())
- throw Class<TypeError>::getInstanceS();
+ throwError<TypeError>(kNullPointerError, "colorTransform");
LOG(LOG_NOT_IMPLEMENTED, "Transform::setColorTransform");
// Set colortransform on th->owner
View
14 src/scripting/flash/net/flashnet.cpp
@@ -89,7 +89,7 @@ tiny_string URLRequest::validatedContentType() const
if(contentType.find("\r")!=contentType.npos ||
contentType.find("\n")!=contentType.npos)
{
- throw Class<ArgumentError>::getInstanceS(tiny_string("Error #2096: The HTTP request header ") + contentType + tiny_string(" cannot be set via ActionScript."));
+ throw Class<ArgumentError>::getInstanceS(tiny_string("The HTTP request header ") + contentType + tiny_string(" cannot be set via ActionScript."), 2096);
}
return contentType;
@@ -124,16 +124,16 @@ void URLRequest::validateHeaderName(const tiny_string& headerName) const
if ((headerName.strchr('\r') != NULL) ||
headerName.strchr('\n') != NULL)
- throw Class<ArgumentError>::getInstanceS("Error #2096: The HTTP request header cannot be set via ActionScript");
+ throw Class<ArgumentError>::getInstanceS("The HTTP request header cannot be set via ActionScript", 2096);
for (unsigned i=0; i<(sizeof illegalHeaders)/(sizeof illegalHeaders[0]); i++)
{
if (headerName.lowercase() == illegalHeaders[i])
{
- tiny_string msg("Error #2096: The HTTP request header ");
+ tiny_string msg("The HTTP request header ");
msg += headerName;
msg += " cannot be set via ActionScript";
- throw Class<ArgumentError>::getInstanceS(msg);
+ throw Class<ArgumentError>::getInstanceS(msg, 2096);
}
}
}
@@ -152,7 +152,7 @@ std::list<tiny_string> URLRequest::getHeaders() const
// Validate
if (!headerObject->is<URLRequestHeader>())
- throw Class<TypeError>::getInstanceS("Error #1034: Object is not URLRequestHeader");
+ throwError<TypeError>(kCheckTypeFailedError, headerObject->getClassName(), "URLRequestHeader");
URLRequestHeader *header = headerObject->as<URLRequestHeader>();
tiny_string headerName = header->name;
validateHeaderName(headerName);
@@ -164,7 +164,7 @@ std::list<tiny_string> URLRequest::getHeaders() const
headerTotalLen += header->name.numBytes();
headerTotalLen += header->value.numBytes();
if (headerTotalLen >= 8192)
- throw Class<ArgumentError>::getInstanceS("Error #2145: Cumulative length of requestHeaders must be less than 8192 characters.");
+ throw Class<ArgumentError>::getInstanceS("Cumulative length of requestHeaders must be less than 8192 characters.", 2145);
// Append header to results
headers.push_back(headerName + ": " + header->value);
@@ -1836,7 +1836,7 @@ ASFUNCTIONBODY(lightspark,getClassByAlias)
const tiny_string& arg0 = args[0]->toString();
auto it=getSys()->aliasMap.find(arg0);
if(it==getSys()->aliasMap.end())
- throw Class<ReferenceError>::getInstanceS("Alias not set");
+ throwError<ReferenceError>(kClassNotFoundError, arg0);
it->second->incRef();
return it->second.getPtr();
View
4 src/scripting/flash/text/flashtext.cpp
@@ -400,7 +400,7 @@ ASFUNCTIONBODY(TextField, _setter_type)
else if (value == "input")
th->type = EDITABLE;
else
- throw Class<ArgumentError>::getInstanceS("Invalid TextField type");
+ throwError<ArgumentError>(kInvalidEnumError, "type");
return NULL;
}
@@ -754,7 +754,7 @@ void TextFormat::onAlign(const tiny_string& old)
align != "left" && align != "right" && align != "start")
{
align = old;
- throw Class<ArgumentError>::getInstanceS();
+ throwError<ArgumentError>(kInvalidEnumError, "align");
}
}
View
3  src/scripting/flash/text/flashtextengine.cpp
@@ -35,7 +35,8 @@ void ContentElement::sinit(Class_base* c)
ASFUNCTIONBODY(ContentElement, _constructor)
{
- throw Class<ArgumentError>::getInstanceS("Error #2012: ContentElement class cannot be instantiated.");
+ throwError<ArgumentError>(kCantInstantiateError, "ContentElement");
+ return NULL;
}
void ElementFormat::sinit(Class_base* c)
View
42 src/scripting/flash/utils/flashutils.cpp
@@ -174,7 +174,7 @@ uint8_t* ByteArray::getBuffer(unsigned int size, bool enableResize)
// so we simply don't allow bytearrays larger than 1GiB
// maybe we should set this smaller
if (size > 0x4000000)
- throw Class<ASError>::getInstanceS("Error #1000: out of memory.");
+ throwError<ASError>(kOutOfMemoryError);
// The first allocation is exactly the size we need,
// the subsequent reallocations happen in increments of BA_CHUNK_SIZE bytes
uint32_t prevLen = len;
@@ -309,7 +309,7 @@ ASFUNCTIONBODY(ByteArray,_setEndian)
else if(args[0]->toString() == Endian::bigEndian)
th->littleEndian = false;
else
- throw Class<ArgumentError>::getInstanceS("Error #2008: Parameter type must be one of the accepted values.");
+ throwError<ArgumentError>(kInvalidEnumError, "endian");
return NULL;
}
@@ -325,7 +325,7 @@ ASFUNCTIONBODY(ByteArray,_setObjectEncoding)
uint32_t value;
ARG_UNPACK(value);
if(value!=ObjectEncoding::AMF0 && value!=ObjectEncoding::AMF3)
- throw Class<ArgumentError>::getInstanceS("Error #2008: Parameter objectEncoding must be one of the accepted values.");
+ throwError<ArgumentError>(kInvalidEnumError, "objectEncoding");
th->objectEncoding=value;
return NULL;
@@ -397,7 +397,7 @@ ASFUNCTIONBODY(ByteArray,readBoolean)
uint8_t ret;
if(!th->readByte(ret))
{
- throw Class<EOFError>::getInstanceS("Error #2030: End of file was encountered.");
+ throwError<ArgumentError>(kEOFError);
}
return abstract_b(ret!=0);
@@ -420,7 +420,7 @@ ASFUNCTIONBODY(ByteArray,readBytes)
//Error checks
if(th->position+length > th->len)
{
- throw Class<EOFError>::getInstanceS("Error #2030: End of file was encountered.");
+ throwError<ArgumentError>(kEOFError);
}
if((uint64_t)length+offset > 0xFFFFFFFF)
{
@@ -455,7 +455,7 @@ ASFUNCTIONBODY(ByteArray,readUTF)
tiny_string res;
if (!th->readUTF(res))
{
- throw Class<EOFError>::getInstanceS("Error #2030: End of file was encountered.");
+ throwError<ArgumentError>(kEOFError);
}
return Class<ASString>::getInstanceS(res);
@@ -469,7 +469,7 @@ ASFUNCTIONBODY(ByteArray,readUTFBytes)
ARG_UNPACK (length);
if(th->position+length > th->len)
{
- throw Class<EOFError>::getInstanceS("Error #2030: End of file was encountered.");
+ throwError<ArgumentError>(kEOFError);
}
uint8_t *bufStart=th->bytes+th->position;
@@ -482,7 +482,7 @@ void ByteArray::writeUTF(const tiny_string& str)
getBuffer(position+str.numBytes()+2,true);
if(str.numBytes() > 65535)
{
- throw Class<RangeError>::getInstanceS("Error #2006: The supplied index is out of bounds.");
+ throwError<RangeError>(kParamRangeError);
}
uint16_t numBytes=endianIn((uint16_t)str.numBytes());
memcpy(bytes+position,&numBytes,2);
@@ -748,7 +748,7 @@ ASFUNCTIONBODY(ByteArray, readByte)
uint8_t ret;
if(!th->readByte(ret))
{
- throw Class<EOFError>::getInstanceS("Error #2030: End of file was encountered.");
+ throwError<ArgumentError>(kEOFError);
}
return abstract_i((int8_t)ret);
}
@@ -760,7 +760,7 @@ ASFUNCTIONBODY(ByteArray,readDouble)
if(th->len < th->position+8)
{
- throw Class<EOFError>::getInstanceS("Error #2030: End of file was encountered.");
+ throwError<ArgumentError>(kEOFError);
}
uint64_t ret;
@@ -779,7 +779,7 @@ ASFUNCTIONBODY(ByteArray,readFloat)
if(th->len < th->position+4)
{
- throw Class<EOFError>::getInstanceS("Error #2030: End of file was encountered.");
+ throwError<ArgumentError>(kEOFError);
}
uint32_t ret;
@@ -798,7 +798,7 @@ ASFUNCTIONBODY(ByteArray,readInt)
if(th->len < th->position+4)
{
- throw Class<EOFError>::getInstanceS("Error #2030: End of file was encountered.");
+ throwError<ArgumentError>(kEOFError);
}
uint32_t ret;
@@ -828,7 +828,7 @@ ASFUNCTIONBODY(ByteArray,readShort)
uint16_t ret;
if(!th->readShort(ret))
{
- throw Class<EOFError>::getInstanceS("Error #2030: End of file was encountered.");
+ throwError<ArgumentError>(kEOFError);
}
return abstract_i((int16_t)ret);
@@ -842,7 +842,7 @@ ASFUNCTIONBODY(ByteArray,readUnsignedByte)
uint8_t ret;
if (!th->readByte(ret))
{
- throw Class<EOFError>::getInstanceS("Error #2030: End of file was encountered.");
+ throwError<ArgumentError>(kEOFError);
}
return abstract_ui(ret);
}
@@ -866,7 +866,7 @@ ASFUNCTIONBODY(ByteArray,readUnsignedInt)
uint32_t ret;
if(!th->readUnsignedInt(ret))
- throw Class<EOFError>::getInstanceS("Error #2030: End of file was encountered.");
+ throwError<ArgumentError>(kEOFError);
return abstract_ui(ret);
}
@@ -879,7 +879,7 @@ ASFUNCTIONBODY(ByteArray,readUnsignedShort)
uint16_t ret;
if(!th->readShort(ret))
{
- throw Class<EOFError>::getInstanceS("Error #2030: End of file was encountered.");
+ throwError<ArgumentError>(kEOFError);
}
return abstract_ui(ret);
@@ -894,7 +894,7 @@ ASFUNCTIONBODY(ByteArray,readMultiByte)
if(th->len < th->position+strlen)
{
- throw Class<EOFError>::getInstanceS("Error #2030: End of file was encountered.");
+ throwError<ArgumentError>(kEOFError);
}
// TODO: should convert from charset to UTF-8
@@ -908,7 +908,7 @@ ASFUNCTIONBODY(ByteArray,readObject)
assert_and_throw(argslen==0);
if(th->bytes==NULL)
{
- throw Class<EOFError>::getInstanceS("Error #2030: End of file was encountered.");
+ throwError<ArgumentError>(kEOFError);
}
assert_and_throw(th->objectEncoding==ObjectEncoding::AMF3);
Amf3Deserializer d(th);
@@ -1052,7 +1052,7 @@ void ByteArray::writeStringVR(map<tiny_string, uint32_t>& stringMap, const tiny_
{
const uint32_t len=s.numBytes();
if(len >= 1<<28)
- throw Class<RangeError>::getInstanceS("Error #2006: The supplied index is out of bounds.");
+ throwError<RangeError>(kParamRangeError);
//Check if the string is already in the map
auto it=stringMap.find(s);
@@ -1084,7 +1084,7 @@ void ByteArray::writeXMLString(std::map<const ASObject*, uint32_t>& objMap,
const tiny_string& xmlstr)
{
if(xmlstr.numBytes() >= 1<<28)
- throw Class<RangeError>::getInstanceS("Error #2006: The supplied index is out of bounds.");
+ throwError<RangeError>(kParamRangeError);
//Check if the XML object has been already serialized
auto it=objMap.find(xml);
@@ -1377,7 +1377,7 @@ ASFUNCTIONBODY(Timer,_setDelay)
assert_and_throw(argslen==1);
int32_t newdelay = args[0]->toInt();
if (newdelay<=0)
- throw Class<ASError>::getInstanceS("delay must be positive");
+ throw Class<RangeError>::getInstanceS("delay must be positive", 2066);
Timer* th=static_cast<Timer*>(obj);
th->delay=newdelay;
View
6 src/scripting/toplevel/Array.cpp
@@ -100,7 +100,7 @@ ASFUNCTIONBODY(Array,_constructor)
{
number_t size=args[0]->toNumber();
if (size < 0 || size > UINT32_MAX)
- throw Class<RangeError>::getInstanceS("");
+ throwError<RangeError>(kArrayIndexNotIntegerError, Number::toString(size));
LOG(LOG_CALLS,_("Creating array of length ") << size);
th->resize((uint32_t)size);
}
@@ -124,7 +124,7 @@ ASFUNCTIONBODY(Array,generator)
{
number_t size=args[0]->toNumber();
if (size < 0 || size > UINT32_MAX)
- throw Class<RangeError>::getInstanceS("");
+ throwError<RangeError>(kArrayIndexNotIntegerError, Number::toString(size));
LOG(LOG_CALLS,_("Creating array of length ") << size);
th->resize((uint32_t)size);
}
@@ -1072,7 +1072,7 @@ ASFUNCTIONBODY(Array,_map)
Array* th=static_cast<Array*>(obj);
if(argslen < 1)
- throw Class<ArgumentError>::getInstanceS("Error #1063: Non-optional argument missing");
+ throwError<ArgumentError>(kWrongArgumentCountError, "Array.map", "1", Integer::toString(argslen));
IFunction* func= NULL;
if (!args[0]->is<RegExp>())
{
View
56 src/scripting/toplevel/Error.cpp
@@ -17,6 +17,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
+#include <sstream>
#include "scripting/toplevel/Error.h"
#include "asobject.h"
#include "scripting/toplevel/toplevel.h"
@@ -26,6 +27,52 @@
using namespace std;
using namespace lightspark;
+tiny_string lightspark::createErrorMessage(int errorID, const tiny_string& arg1, const tiny_string& arg2, const tiny_string& arg3)
+{
+ auto found = errorMessages.find(errorID);
+ if (found == errorMessages.end())
+ return "";
+
+ //Replace "%1", "%2" and "%3" with the optional arguments
+ stringstream msg;
+ const char *msgtemplate = found->second;
+ assert(msgtemplate);
+ while (*msgtemplate)
+ {
+ if (*msgtemplate == '%')
+ {
+ msgtemplate++;
+ switch (*msgtemplate)
+ {
+ case '1':
+ msg << arg1;
+ break;
+ case '2':
+ msg << arg2;
+ break;
+ case