IReferenceResolver.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Jint.Native;
  2. namespace Jint.Runtime.Interop
  3. {
  4. /// <summary>
  5. /// Reference resolver allows customizing behavior for reference resolving. This can be useful in cases where
  6. /// you want to ignore long chain of property accesses that might throw if anything is null or undefined.
  7. /// An example of such is <code>var a = obj.field.subField.value</code>. Custom resolver could accept chain to return
  8. /// null/undefined on first occurrence.
  9. /// </summary>
  10. public interface IReferenceResolver
  11. {
  12. /// <summary>
  13. /// When unresolvable reference occurs, check if another value can be provided instead of it.
  14. /// </summary>
  15. /// <remarks>
  16. /// A reference error will be thrown if this method return false.
  17. /// </remarks>
  18. /// <param name="engine">The current engine instance.</param>
  19. /// <param name="reference">The reference that is being processed.</param>
  20. /// <param name="value">Value that should be used instead of undefined.</param>
  21. /// <returns>Whether to use <paramref name="value" /> instead of undefined.</returns>
  22. bool TryUnresolvableReference(Engine engine, Reference reference, out JsValue value);
  23. /// <summary>
  24. /// When property reference is being processed, resolve to other value if needed.
  25. /// </summary>
  26. /// <param name="engine">The current engine instance.</param>
  27. /// <param name="reference">The reference that is being processed.</param>
  28. /// <param name="value">Value that should be used instead of reference target.</param>
  29. /// <returns>Whether to use <paramref name="value" /> instead of reference's value.</returns>
  30. bool TryPropertyReference(Engine engine, Reference reference, ref JsValue value);
  31. /// <summary>
  32. /// When evaluating a function call and a target that is not an object is encountered,
  33. /// custom implementation can return a value to call.
  34. /// </summary>
  35. /// <remarks>
  36. /// A reference error will be thrown if this method return false.
  37. /// </remarks>
  38. /// <param name="engine">The current engine instance.</param>
  39. /// <param name="callee">The callee.</param>
  40. /// <param name="value">Value that should be used when this method return true. Should be <see cref="ICallable"/>.</param>
  41. /// <returns>Whether to use <paramref name="value" /> instead of undefined.</returns>
  42. bool TryGetCallable(Engine engine, object callee, out JsValue value);
  43. /// <summary>
  44. /// Check whether objects property value is valid.
  45. /// </summary>
  46. /// <param name="value">The value to check</param>
  47. /// <returns>Whether to accept the value.</returns>
  48. bool CheckCoercible(JsValue value);
  49. }
  50. }