IReferenceResolver.cs 2.8 KB

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