Bug Description
When repairing Hermes intrinsics via Secure EcmaScript to reach spec compliancy
we detect non-standard/deprecated .caller and .arguments properties on several intrinsics
so have an expedient temp fix (proposed) to account for these
but would love to understand what Hermes is trying to do and the path towards spec-compliancy cc @tmikov @erights
some more details
https://github.com/facebook/hermes/blob/main/doc/Features.md#miscellaneous-incompatibilities
arguments changes in non-strict mode will not sync with named parameters
ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode#no_syncing_between_parameters_and_arguments_indices
hermes
|
CallResult<HermesValue> |
|
throwTypeError(void *ctx, Runtime &runtime, NativeArgs) { |
|
static const char *TypeErrorMessage[] = { |
|
"Restricted in strict mode", |
|
"Dynamic requires are not allowed after static resolution", |
|
}; |
|
|
|
uint64_t kind = (uint64_t)ctx; |
|
assert( |
|
kind < (uint64_t)TypeErrorKind::NumKinds && |
|
"[[ThrowTypeError]] wrong error kind passed as context"); |
|
return runtime.raiseTypeError(TypeErrorMessage[kind]); |
|
} |
|
print('function properties'); |
|
// CHECK-LABEL: function properties |
|
print(typeof strict, typeof nonStrict); |
|
// CHECK-NEXT: function function |
|
print(nonStrict.caller, nonStrict.arguments); |
|
// CHECK-NEXT: undefined undefined |
|
try { print(strict.caller); } catch(e) { print('caught', e.name, e.message); } |
|
// CHECK-NEXT: caught TypeError Restricted in strict mode |
|
try { print(strict.arguments); } catch(e) { print('caught', e.name, e.message); } |
|
// CHECK-NEXT: caught TypeError Restricted in strict mode |
|
|
|
var bound = nonStrict.bind(42); |
|
try { print(bound.caller); } catch(e) { print('caught', e.name, e.message); } |
|
// CHECK-NEXT: caught TypeError Restricted in strict mode |
|
try { print(bound.arguments); } catch(e) { print('caught', e.name, e.message); } |
|
// CHECK-NEXT: caught TypeError Restricted in strict mode |
static_h
|
CallResult<HermesValue> |
|
throwTypeError(void *ctx, Runtime &runtime, NativeArgs) { |
|
static const char *TypeErrorMessage[] = { |
|
"Restricted property cannot be accessed", |
|
"Dynamic requires are not allowed after static resolution", |
|
}; |
|
|
|
uint64_t kind = (uint64_t)ctx; |
|
assert( |
|
kind < (uint64_t)TypeErrorKind::NumKinds && |
|
"[[ThrowTypeError]] wrong error kind passed as context"); |
|
return runtime.raiseTypeError(TypeErrorMessage[kind]); |
|
} |
|
print('function properties'); |
|
// CHECK-LABEL: function properties |
|
print(typeof strict, typeof nonStrict); |
|
// CHECK-NEXT: function function |
|
try { print(nonStrict.caller); } catch(e) { print('caught', e.name, e.message); } |
|
// CHECK-NEXT: caught TypeError Restricted property cannot be accessed |
|
try { print(nonStrict.arguments); } catch(e) { print('caught', e.name, e.message); } |
|
// CHECK-NEXT: caught TypeError Restricted property cannot be accessed |
|
try { print(strict.caller); } catch(e) { print('caught', e.name, e.message); } |
|
// CHECK-NEXT: caught TypeError Restricted property cannot be accessed |
|
try { print(strict.arguments); } catch(e) { print('caught', e.name, e.message); } |
|
// CHECK-NEXT: caught TypeError Restricted property cannot be accessed |
|
|
|
var bound = nonStrict.bind(42); |
|
try { print(bound.caller); } catch(e) { print('caught', e.name, e.message); } |
|
// CHECK-NEXT: caught TypeError Restricted property cannot be accessed |
|
try { print(bound.arguments); } catch(e) { print('caught', e.name, e.message); } |
|
// CHECK-NEXT: caught TypeError Restricted property cannot be accessed |
|
|
|
try { print(Function.prototype.caller); } catch(e) { print('caught', e.name, e.message); } |
|
// CHECK-NEXT: caught TypeError Restricted property cannot be accessed |
|
try { print(Function.prototype.arguments); } catch(e) { print('caught', e.name, e.message); } |
|
// CHECK-NEXT: caught TypeError Restricted property cannot be accessed |
Bug Description
When repairing Hermes intrinsics via Secure EcmaScript to reach spec compliancy
removeUnpermittedIntrinsicson Hermes endojs/endo#2655we detect non-standard/deprecated
.callerand.argumentsproperties on several intrinsicsso have an expedient temp fix (proposed) to account for these
but would love to understand what Hermes is trying to do and the path towards spec-compliancy cc @tmikov @erights
some more details
Function.callersupport Hermes workaround, WIPremoveUnpermittedIntrinsicson Hermes endojs/endo#2655 (comment)https://github.com/facebook/hermes/blob/main/doc/Features.md#miscellaneous-incompatibilities
ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode#no_syncing_between_parameters_and_arguments_indices
hermes
hermes/lib/VM/JSLib/GlobalObject.cpp
Lines 246 to 258 in 95b2b52
hermes/test/hermes/function-non-strict.js
Lines 18 to 33 in 95b2b52
static_h
hermes/lib/VM/JSLib/GlobalObject.cpp
Lines 247 to 259 in 696b483
hermes/test/hermes/function-non-strict.js
Lines 19 to 41 in 696b483