Skip to content

Strictness, caller and arguments spec compliancy #1582

@leotm

Description

@leotm

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed-in-shFixed in SH but "wontfix" in Hermes

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions