Skip to content

Commit

Permalink
v8: Object.defineProperty work with process.env
Browse files Browse the repository at this point in the history
  • Loading branch information
pmq20 committed Sep 22, 2015
1 parent d6a6ec2 commit 76db621
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
12 changes: 12 additions & 0 deletions deps/v8/src/runtime/runtime-object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,8 @@ RUNTIME_FUNCTION(Runtime_DefineDataPropertyUnchecked) {
CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3);

LookupIterator it(js_object, name, LookupIterator::OWN_SKIP_INTERCEPTOR);
LookupIterator it_interceptor(js_object, name, LookupIterator::OWN);

if (it.IsFound() && it.state() == LookupIterator::ACCESS_CHECK) {
if (!isolate->MayAccess(js_object)) {
return isolate->heap()->undefined_value();
Expand All @@ -1407,6 +1409,16 @@ RUNTIME_FUNCTION(Runtime_DefineDataPropertyUnchecked) {
return *result;
}

// If there's an interceptor, try to store the property with the
// interceptor.
if (it_interceptor.state() == LookupIterator::INTERCEPTOR) {
Handle<Object> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result,
JSObject::SetPropertyWithInterceptor(&it_interceptor, obj_value));
return *result;
}

Handle<Object> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result,
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-process-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ if (process.argv[2] == 'you-are-the-child') {
delete process.env.NODE_PROCESS_ENV_DELETED;
assert.equal(false, 'NODE_PROCESS_ENV_DELETED' in process.env);

Object.defineProperty(process.env, 'NODE_PROCESS_ENV_DELETED', {
writable: true,
configurable: true,
enumerable: true,
value: 0
});
assert.equal(true, 'NODE_PROCESS_ENV_DELETED' in process.env);

delete process.env.NODE_PROCESS_ENV_DELETED;
assert.equal(false, 'NODE_PROCESS_ENV_DELETED' in process.env);

var child = spawn(process.argv[0], [process.argv[1], 'you-are-the-child']);
child.stdout.on('data', function(data) { console.log(data.toString()); });
child.stderr.on('data', function(data) { console.log(data.toString()); });
Expand Down

0 comments on commit 76db621

Please sign in to comment.