Fix JS error getting F=F text from ComposerWebView. Add JS unit tests.

* ui/composer-web-view.js (ComposerPageState::resolveNesting): Apply JS
  RegExp globally, to match default GLib RegEx behaviour.

* test/js/composer-page-state-test.vala: New tests covering generation of
  HTML and F=F text from JS ComposerPageState object.

* test/CMakeLists.txt: Add the new test.

* test/main.vala (main): Add a test suite for JS tests, add the new test
  to it.

* src/client/components/client-web-view.vala (ClientWebView): Add a
  reason to the JSError domain for when a JS exception is thrown.

* bindings/vapi/javascriptcore-4.0.vapi (JS::Context): Add JS.Type and
  some additional methods needed for the unit tests. Move most
  GlobalContext methods to Context so we can pass the lowest common
  demominator around.
This commit is contained in:
Michael James Gratton 2017-01-01 12:37:08 +11:00
parent 5dc20f4273
commit 22de6b122e
6 changed files with 283 additions and 12 deletions

View file

@ -3,9 +3,9 @@
[CCode (cprefix = "JS", gir_namespace = "JavaScriptCore", gir_version = "4.0", lower_case_cprefix = "JS_", cheader_filename = "JavaScriptCore/JavaScript.h")]
namespace JS {
[CCode (cname = "JSGlobalContextRef")]
[CCode (cname = "JSContextRef")]
[SimpleType]
public struct GlobalContext : Context {
public struct Context {
[CCode (cname = "JSValueIsBoolean")]
public bool is_boolean(JS.Value value);
@ -13,23 +13,21 @@ namespace JS {
[CCode (cname = "JSValueIsNumber")]
public bool is_number(JS.Value value);
[CCode (cname = "JSValueIsObject")]
public bool is_object(JS.Value value);
[CCode (cname = "JSValueToBoolean")]
public bool to_boolean(JS.Value value);
[CCode (cname = "JSValueToNumber")]
public double to_number(JS.Value value, out JS.Value exception);
[CCode (cname = "JSValueToObject")]
public Object to_object(JS.Value value, out JS.Value exception);
[CCode (cname = "JSValueToStringCopy")]
public String to_string_copy(JS.Value value, out JS.Value exception);
[CCode (cname = "JSGlobalContextRelease")]
public bool release();
}
[CCode (cname = "JSContextRef")]
[SimpleType]
public struct Context {
[CCode (cname = "JSEvaluateScript")]
public Value evaluate_script(String script,
Object? thisObject,
@ -55,14 +53,35 @@ namespace JS {
}
[CCode (cname = "JSGlobalContextRef")]
[SimpleType]
public struct GlobalContext : Context {
[CCode (cname = "JSGlobalContextRelease")]
public bool release();
}
[CCode (cname = "JSObjectRef")]
[SimpleType]
public struct Object {
[CCode (cname = "JSObjectHasProperty", instance_pos = 1.1)]
public bool has_property(Context ctx, String property_name);
[CCode (cname = "JSObjectGetProperty", instance_pos = 1.1)]
public String get_property(Context ctx,
String property_name,
out Value? exception);
}
[CCode (cname = "JSValueRef")]
[SimpleType]
public struct Value {
[CCode (cname = "JSValueGetType", instance_pos = 1.1)]
public JS.Type get_type(JS.Context context);
}
[CCode (cname = "JSStringRef", ref_function = "JSStringRetain", unref_function = "JSStringRelease")]
@ -88,4 +107,27 @@ namespace JS {
public void String.release();
}
[CCode (cname = "JSType", has_type_id = false)]
public enum Type {
[CCode (cname = "kJSTypeUndefined")]
UNDEFINED,
[CCode (cname = "kJSTypeNull")]
NULL,
[CCode (cname = "kJSTypeBoolean")]
BOOLEAN,
[CCode (cname = "kJSTypeNumber")]
NUMBER,
[CCode (cname = "kJSTypeString")]
STRING,
[CCode (cname = "kJSTypeObject")]
OBJECT
}
}